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

Add "has-network" attribute #9

Merged
merged 1 commit into from
Jan 16, 2024
Merged

Conversation

nickautomatic
Copy link
Contributor

Description

This introduces a has-network attribute which allows us to show or hide things based on network status ("online" or "offline")

One thing that might be worth noting: when has-network is present but set to an invalid value (ie. something other than online or offline) the matcher will always return false. I wasn't totally sure what the best approach here was: another option would be to return undefined and effectively ignore the matcher, but treating other values as false seemed more consistent with how the other conditional attributes behave in cases where a value is invalid, and maybe less likely to lead to confusion where someone, eg. makes a typo.

Related Issue(s)

An earlier attempt at this used an is-offline attribute. However, on that PR, @mirisuzanne suggested that has-network="offline | online" might be a better syntax. I agree, because this has the advantage of putting "online" and "offline" on the same logical footing, making "online" equally targetable for showing / hiding purposes, rather than treating it as a default state.

Steps to test/reproduce

Use the has-network attribute to show/hide based on network status:

<show-when has-network="online">This is visible when we're online</hide-when>
<show-when has-network="offline">...and this is only visible when we're offline</show-when>

This allows us to show or hide things based on network status.
Allowable values are "online" or "offline".

An [earlier attempt][1] at this introduced an `is-offline` attribute,
but the disadvantage of this approach is that "online" is an implicit
default state. The approach here puts "online" and "offline" on the same
logical footing, and allows them to be combined with other conditions
more easily.

Note that if a value other than "offline" or "online" is provided to
`has-network` it will always return false. This seemed the most
consistent approach with other matchers (eg. supports, media, etc).

[1]: oddbird#7
Copy link
Contributor

@jamesnw jamesnw left a comment

Choose a reason for hiding this comment

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

This looks great! I agree that returning false for invalid values of has-network is the way to go- thanks for thinking that through!

Copy link
Member

@mirisuzanne mirisuzanne left a comment

Choose a reason for hiding this comment

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

looks great, thanks!

@mirisuzanne mirisuzanne merged commit 64227cd into oddbird:main Jan 16, 2024
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.

3 participants