-
Notifications
You must be signed in to change notification settings - Fork 80
feat(switch): enhance component's colors for a11y and usability #11951
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
Changes from 2 commits
756f5db
116f709
b878f6c
4b4f726
40131f1
f740256
4812e82
3ad5381
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,11 +4,12 @@ | |||||
* These properties can be overridden using the component's tag as selector. | ||||||
* | ||||||
* @prop --calcite-switch-background-color: Specifies the component's background color. | ||||||
* @prop --calcite-switch-border-color: Specifies the component's border color. | ||||||
* @prop --calcite-switch-background-color-hover: Specifies the component's background color when hovered or pressed. | ||||||
* @prop --calcite-switch-border-color: [Deprecated] Specifies the component's border color. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we specify any deprecation reasoning or what they should use instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't have other similar references across our CSS doc, but since the border is no longer applicable, maybe we could go with:
Suggested change
cc @DitwanP |
||||||
* @prop --calcite-switch-corner-radius: Specifies the component's corner radius. | ||||||
* @prop --calcite-switch-handle-background-color: Specifies the handle's background color. | ||||||
* @prop --calcite-switch-handle-border-color: Specifies the handle's border color. | ||||||
* @prop --calcite-switch-handle-shadow: Specifies the handle's shadow. | ||||||
* @prop --calcite-switch-handle-border-color: [Deprecated] Specifies the handle's border color. | ||||||
* @prop --calcite-switch-handle-shadow: [Deprecated] Specifies the handle's shadow. | ||||||
*/ | ||||||
|
||||||
// sizes | ||||||
|
@@ -69,59 +70,65 @@ | |||||
relative | ||||||
box-border | ||||||
inline-block | ||||||
border | ||||||
border-solid | ||||||
align-top | ||||||
focus-base; | ||||||
|
||||||
border-radius: var(--calcite-switch-corner-radius, 9999px); | ||||||
border-color: var(--calcite-switch-border-color, var(--calcite-color-border-2)); | ||||||
background-color: var(--calcite-switch-background-color, var(--calcite-color-foreground-2)); | ||||||
border-color: var(--calcite-switch-border-color); | ||||||
background-color: var(--calcite-switch-background-color, var(--calcite-color-border-input)); | ||||||
} | ||||||
|
||||||
.container:focus .track { | ||||||
@apply focus-outset; | ||||||
} | ||||||
|
||||||
.container:hover .track { | ||||||
background-color: var(--calcite-switch-background-color-hover, var(--calcite-color-text-3)); | ||||||
} | ||||||
|
||||||
.handle { | ||||||
@apply pointer-events-none | ||||||
absolute | ||||||
block | ||||||
border-2 | ||||||
border-solid | ||||||
transition-all | ||||||
duration-150 | ||||||
ease-in-out; | ||||||
inset-block-start: -1px; | ||||||
inset-inline: -1px theme("inset.auto"); | ||||||
inset-block-start: 2px; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a platform design token that can be used here? Maybe a border width one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated this to use |
||||||
inset-inline: 2px theme("inset.auto"); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I couldn't find a css var with |
||||||
background-color: var(--calcite-switch-handle-background-color, var(--calcite-color-foreground-1)); | ||||||
border-color: var(--calcite-switch-handle-border-color, var(--calcite-color-border-input)); | ||||||
border-color: var(--calcite-switch-handle-border-color); | ||||||
border-radius: var(--calcite-switch-corner-radius, 9999px); | ||||||
box-shadow: var(--calcite-switch-handle-shadow); | ||||||
} | ||||||
|
||||||
:host(:hover:not([disabled])), | ||||||
:host(:focus:not([disabled])) { | ||||||
.handle { | ||||||
border-color: var(--calcite-switch-handle-border-color, var(--calcite-color-brand)); | ||||||
box-shadow: var(--calcite-switch-handle-shadow, inset 0 0 0 1px var(--calcite-color-brand)); | ||||||
border-color: var(--calcite-switch-handle-border-color); | ||||||
box-shadow: var(--calcite-switch-handle-shadow, inset 0 0 0 0); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we still need to set box-shadow here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed this, thanks for catching it! |
||||||
} | ||||||
} | ||||||
|
||||||
:host([checked]) { | ||||||
.track { | ||||||
border-color: var(--calcite-switch-border-color, var(--calcite-color-brand-hover)); | ||||||
border-color: var(--calcite-switch-border-color); | ||||||
background-color: var(--calcite-switch-background-color, var(--calcite-color-brand)); | ||||||
} | ||||||
.handle { | ||||||
border-color: var(--calcite-switch-handle-border-color, var(--calcite-color-brand)); | ||||||
inset-inline: theme("inset.auto") -1px; | ||||||
border-color: var(--calcite-switch-handle-border-color); | ||||||
inset-inline: theme("inset.auto") 2px; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a platform design token that can be used here? Maybe a border width one? can the theme() be replaced with a css var? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the inset-inline could be |
||||||
} | ||||||
|
||||||
&:host(:hover:not([disabled])) { | ||||||
.track { | ||||||
background-color: var(--calcite-switch-background-color-hover, var(--calcite-color-brand-hover)); | ||||||
} | ||||||
} | ||||||
|
||||||
&:host(:hover:not([disabled])) { | ||||||
.handle { | ||||||
border-color: var(--calcite-switch-handle-border-color, var(--calcite-color-brand-hover)); | ||||||
box-shadow: var(--calcite-switch-handle-shadow, inset 0 0 0 1px var(--calcite-color-brand-hover)); | ||||||
driskull marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
border-color: var(--calcite-switch-handle-border-color); | ||||||
box-shadow: var(--calcite-switch-handle-shadow, inset 0 0 0 0); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we still need to set box-shadow here? |
||||||
} | ||||||
} | ||||||
} | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add this var to the switch custom theme story tokens?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this, thanks for catching it!