[BOOKINGSG-9121][Nghi] migrate toggle and toggle-icon style to linaria#1104
[BOOKINGSG-9121][Nghi] migrate toggle and toggle-icon style to linaria#1104nghitb wants to merge 14 commits intopre-release/v4from
Conversation
There was a problem hiding this comment.
Let's add a unit test for the component.
@qroll should we also have a e2e story for this component as well?
There was a problem hiding this comment.
yep we should be adding the unit tests too
There was a problem hiding this comment.
yep we should be adding the unit tests too
| export const removeButtonDisabled = css` | ||
| color: ${Colour["text-disabled"]}; | ||
| cursor: not-allowed; | ||
| `; |
There was a problem hiding this comment.
This has the same content with expandButtonDisabled & errorContainerDisabled. How about we make this as a general disabled class name?
| export const toggleTextContainerDisabled = css` | ||
| color: ${Colour["text-disabled"]}; | ||
| `; |
There was a problem hiding this comment.
This is similar with childrenDisabled, errorTextDisabled & errorListDisabled. Lets have a general disabled text class name
| export const errorText = css` | ||
| color: ${Colour["text-error"]}; | ||
| `; |
| export const toggleContainerNoBorderErrorDisabled = css` | ||
| border-color: ${Colour["border-error"]}; | ||
| `; |
There was a problem hiding this comment.
This is similar with toggleContainerDefaultErrorDisabled
| &:has(.${headerContainer}:hover) { | ||
| @media (pointer: fine) { | ||
| background: ${Colour["bg-hover-subtle"]}; | ||
| } | ||
| } |
There was a problem hiding this comment.
I see a pattern where we have two type of hover styling, for default and selected. Let's extract those to a class name and reference it
There was a problem hiding this comment.
im confused, can u give an example
There was a problem hiding this comment.
Okay, so we can have something like this
const defaultHoverBlock = `
&:has(.${headerContainer}:hover) {
@media (pointer: fine) {
background: ${Colour["bg-hover-subtle"]};
}
}
`;
const selectedHoverBlock = `
&:has(.${headerContainer}:hover) {
@media (pointer: fine) {
background: ${Colour["bg-selected-hover"]};
& .${textContainer} {
color: ${Colour["text-selected-hover"]};
}
& .${toggleIconStyles.wrapperBase} {
color: ${Colour["icon-selected-hover"]};
}
}
}
`;
and then reference them like
export const toggleContainerNoBorderError = css`
border-color: ${Colour["border-error"]};
${defaultHoverBlock}
`;
export const toggleContainerDefaultSelected = css`
border-color: ${Colour["border-selected"]};
background: ${Colour["bg-selected"]};
${selectedHoverBlock}
`;
But this makes them just like a regular string
There was a problem hiding this comment.
Or if we want to avoid having literal string, we can introduce a hover class name
There was a problem hiding this comment.
if we change to a hover classname, it will make the getContainerStateClass more complicated
There was a problem hiding this comment.
We don't have to touch getContainerStateClass. Can instead introduce a new helper for the hover
const getContainerHoverClass = (() => {
if (disabled) {
return undefined;
}
if (!error && selected) {
return styles.toggleContainerHoverSelected;
}
return styles.toggleContainerHoverDefault;
})();
What do you think?
| checked | ||
| error |
There was a problem hiding this comment.
error and checked are mutually exclusive
| test.describe(() => { | ||
| test.beforeEach(async ({ story }) => { | ||
| await story.init("with-sublabel", { mode: "dark" }); | ||
| }); | ||
|
|
||
| test("With sub label (dark mode)", async ({ story }) => { | ||
| await compareScreenshot(story, "mount"); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
I don't we need dark mode here, already covered by base variants
| test.describe(() => { | ||
| test.beforeEach(async ({ story }) => { | ||
| await story.init("with-composite", { mode: "dark" }); | ||
| }); | ||
|
|
||
| test("With composite section (dark mode)", async ({ story }) => { | ||
| await compareScreenshot(story, "mount"); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
I don't we need dark mode here, already covered by base variants
| @@ -0,0 +1,134 @@ | |||
| import { test as base, Page } from "@playwright/test"; | |||
There was a problem hiding this comment.
Add a case for keyboard navigation and also check for focusableWhenDisabled
Checklist
classNameis chained correctly withclsx