Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

92 Describe all 3 days of predictions and distinguish current tab #65

Merged

Conversation

edavey
Copy link
Collaborator

@edavey edavey commented Oct 24, 2024

In this PR with

  • describe predictions for each of the 3 days (in addition to today's tab)
  • distinguish current tab

@edavey
Copy link
Collaborator Author

edavey commented Oct 24, 2024

@patrickjfl patrickjfl force-pushed the 92-migrate-air-quality-alert-integration-tests-to-new-design branch from fc1e272 to 94640ba Compare October 24, 2024 14:55
@edavey edavey changed the title 92 migrate air quality alert integration tests to new design 92 Describe all 3 days of predictions and distinguish current tab Oct 24, 2024
@edavey edavey marked this pull request as ready for review October 24, 2024 15:15
Hotwire includes the Stimulus project for JS "sprinkles".
See: https://stimulus.hotwired.dev

and https://stimulus.hotwired.dev/handbook/origin
for some background.

Our immediate task is to visually identify the active tab
(either today, tomorrow or the day after tomorrow). We'll
add an `.active` class to the appropriate tab,
e.g. `.tab.tomorrow.active`.

Let's see if we can do this in a low code way which is easy
to maintain using Stimulus...
We define a JS TagController which is instantated 3
times, once for each tag.

There's some magic (or convention) being used here:

TARGET

`static targets = [ "day" ]` identifies the DOM element
to which we wish to bind: `"data-tab-target" = "day"`

We then refer to this element with `this.dayTarget`

CLASS HELPER

`static classes = [ "active" ]`

similar to the `dayTarget` we can now reference our active
class as `this.activeClass`

As we've now got 4 data attributes I've used the Rails
[`tag()` method][] so that we can group our data attributes
under the `data` key which I think helps readability:

```
<%= tag.div class: "tab py-4 ...",
data: {
  date: forecast.date.to_s,
  controller: "tab",
  "tab-active-class": "active",
  "tab-target": "day"
} do
%>
```

[`tag()` method][]:
https://apidock.com/rails/ActionView/Helpers/TagHelper/tag
@patrickjfl patrickjfl force-pushed the 92-migrate-air-quality-alert-integration-tests-to-new-design branch from 94640ba to 2e6154a Compare October 24, 2024 15:17
Copy link
Contributor

@patrickjfl patrickjfl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice job getting Stimulus sorted 🙌

https://tailwindcss.com/docs/functions-and-directives#apply

I have also changed made the text colour for the inactive tabs slightly darker so that it is more readable.
@patrickjfl patrickjfl force-pushed the 92-migrate-air-quality-alert-integration-tests-to-new-design branch from 2e6154a to 72a0aa0 Compare October 24, 2024 15:30
@edavey edavey merged commit 0f3d6f2 into develop Oct 24, 2024
2 checks passed
@edavey edavey deleted the 92-migrate-air-quality-alert-integration-tests-to-new-design branch October 24, 2024 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants