Skip to content

Commit 2d0f954

Browse files
aesteves60dpellier
authored andcommitted
fix(toggle): review
1 parent 5682374 commit 2d0f954

File tree

13 files changed

+173
-49
lines changed

13 files changed

+173
-49
lines changed

packages/ods/src/components/toggle/src/components/ods-toggle/ods-toggle.scss

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
position: absolute;
2121
bottom: 2px;
2222
left: 2px;
23-
transition: .4s;
23+
transition: all .4s ease;
24+
z-index: 1;
2425
border-radius: 1rem;
26+
box-shadow: 0 1px 1px 0#00000040;
2527
background-color: var(--ods-color-neutral-000);
2628
width: 20px;
2729
height: 20px;
@@ -39,16 +41,25 @@
3941
&--disabled {
4042
background-color: var(--ods-color-neutral-100);
4143
cursor: not-allowed;
44+
45+
& #{$slider}__label {
46+
color: var(--ods-color-neutral-600);
47+
}
4248
}
4349

4450
&__label {
51+
display: flex;
4552
position: absolute;
46-
top: 5px;
47-
left: 23px;
53+
top: 0;
54+
right: 0;
55+
bottom: 0;
56+
align-items: center;
57+
padding-right: 2px;
4858
color: var(--ods-color-neutral-700);
4959
font-size: 12px;
5060
font-weight: 700;
5161
pointer-events: none;
62+
user-select: none;
5263
}
5364
}
5465

@@ -67,7 +78,8 @@
6778
}
6879

6980
& + .ods-toggle__container__slider .ods-toggle__container__slider__label {
70-
left: 4px;
81+
left: 0;
82+
padding-left: 4px;
7183
}
7284

7385
& + :not(.ods-toggle__container__slider--disabled).ods-toggle__container__slider {

packages/ods/src/components/toggle/tests/behaviour/ods-toggle.e2e.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('ods-toggle behaviour', () => {
3535
expect(odsChangeSpy).toHaveReceivedEventTimes(1);
3636
});
3737

38-
it('should toggle value if disabled', async() => {
38+
it('should not toggle value if disabled', async() => {
3939
await setup('<ods-toggle is-disabled></ods-toggle>');
4040
const odsChangeSpy = await page.spyOnEvent('odsChange');
4141

packages/ods/src/components/toggle/tests/rendering/ods-toggle.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ describe('ods-toggle rendering', () => {
9292

9393
describe('withLabel', () => {
9494
it('should be reflected', async() => {
95-
await setup('<ods-toggle withLabel></ods-toggle>');
95+
await setup('<ods-toggle with-label></ods-toggle>');
9696

97-
expect(root?.getAttribute('withLabel')).toBe('');
97+
expect(root?.getAttribute('with-label')).toBe('');
9898
});
9999

100100
it('should not be set by default', async() => {
101101
await setup('<ods-toggle></ods-toggle>');
102102

103-
expect(root?.getAttribute('withLabel')).toBeNull();
103+
expect(root?.getAttribute('with-label')).toBeNull();
104104
});
105105
});
106106
});

packages/storybook/stories/components/badge/documentation.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ Custom badge css:
2828

2929
# Examples
3030

31-
## Usage
32-
33-
### Default
31+
## Default
3432

3533
<Canvas of={ BadgeStories.Default } sourceState='shown' />
3634

packages/storybook/stories/components/link/documentation.mdx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,18 @@ Custom link css:
2828

2929
# Examples
3030

31-
## Usage
32-
33-
### Default
31+
## Default
3432

3533
<Canvas of={ LinkStories.Default } sourceState='shown' />
3634

37-
### Color
35+
## Color
3836
<Canvas of={ LinkStories.Color } sourceState='shown' />
3937

40-
### Disabled
38+
## Disabled
4139
<Canvas of={ LinkStories.Disabled } sourceState='shown' />
4240

43-
### Icon
41+
## Icon
4442
<Canvas of={ LinkStories.Icon } sourceState='shown' />
4543

46-
### Target
44+
## Target
4745
<Canvas of={ LinkStories.Target } sourceState='shown' />

packages/storybook/stories/components/quantity/documentation.mdx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,25 @@ Custom quantity css:
2828

2929
# Examples
3030

31-
## Usage
32-
33-
### Default
31+
## Default
3432

3533
<Canvas of={ QuantityStories.Default } sourceState='shown' />
3634

37-
### Disabled
35+
## Disabled
3836
<Canvas of={ QuantityStories.Disabled } sourceState='shown' />
3937

40-
### Error
38+
## Error
4139
<Canvas of={ QuantityStories.Error } sourceState='shown' />
4240

43-
### Max
41+
## Max
4442
<Canvas of={ QuantityStories.Max } sourceState='shown' />
4543

46-
### Min
44+
## Min
4745
<Canvas of={ QuantityStories.Min } sourceState='shown' />
4846

49-
### Readonly
47+
## Readonly
5048
<Canvas of={ QuantityStories.Readonly } sourceState='shown' />
5149

52-
### Step
50+
## Step
5351
<Canvas of={ QuantityStories.Step } sourceState='shown' />
5452

packages/storybook/stories/components/skeleton/documentation.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ You can add your own style on the text element using the part `skeleton`.
2525
<Canvas of={ SkeletonStories.CustomCSS } sourceState='shown'/>
2626

2727
# Examples
28+
2829
## Default
2930

3031
<Canvas of={ SkeletonStories.Default } sourceState='shown' />

packages/storybook/stories/components/table/documentation.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ You can apply your own style on each part of the table directly.
2626

2727
# Examples
2828

29-
## Usage
30-
31-
### Default
29+
## Default
3230

3331
<Canvas of={ TableStories.Default } sourceState='shown' />
3432

packages/storybook/stories/components/tag/documentation.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ You can add your own style on the tag element using the part `tag`.
2626

2727
# Examples
2828

29-
## Usage
30-
31-
### Default
29+
## Default
3230

3331
<Canvas of={ TagStories.Default } sourceState='shown' />
3432

packages/storybook/stories/components/toggle/documentation.mdx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,23 @@ Toggle component is used to allow the user to switch between two states, on and
1818

1919
<Markdown>{ SpecificationsToggle }</Markdown>
2020

21-
# Examples
21+
# Style customization
22+
23+
You can add your own style on the text element using the part `slider`, `label`, `slider check` or `label check`.
2224

23-
## Usage
25+
<Canvas of={ ToggleStories.CustomCSS } sourceState='shown'/>
26+
27+
# Examples
2428

25-
### Default
29+
## Default
2630

2731
<Canvas of={ ToggleStories.Default } sourceState='shown' />
2832

29-
### Disabled On
33+
## Disabled On
3034
<Canvas of={ ToggleStories.DisabledOn } sourceState='shown' />
3135

32-
### Disabled Off
36+
## Disabled Off
3337
<Canvas of={ ToggleStories.DisabledOff } sourceState='shown' />
3438

35-
### With Label
39+
## With Label
3640
<Canvas of={ ToggleStories.WithLabel } sourceState='shown' />

packages/storybook/stories/components/toggle/migration.from.17.x.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ You can use the new `value` attribute to obtain the same behavior.
1818

1919
Has been removed.
2020

21-
Design team doesn't valid this style anymore.
21+
This design feature has been removed in order to match the new styling of the component.
2222

2323
`contrasted` <img src="https://img.shields.io/badge/removed-FF0000" />
2424

2525
Has been removed.
2626

27-
Design team doesn't valid this style anymore.
27+
This design feature has been removed in order to match the new styling of the component.
2828

2929
`color` <img src="https://img.shields.io/badge/removed-FF0000" />
3030

3131
Has been removed.
3232

33-
Design team doesn't valid this style anymore.
33+
This design feature has been removed in order to match the new styling of the component.
3434

3535
`disabled` <img src="https://img.shields.io/badge/updated-00FFFF" />
3636

@@ -54,13 +54,13 @@ Defines if the toggle is required in a form.
5454

5555
New attribute.
5656

57-
You can use the new name attribute for set an identifiant in a form.
57+
You can use the new 'name' attribute to identify your OdsToggle within a form.
5858

5959
`withLabel` <img src="https://img.shields.io/badge/new-008000" />
6060

6161
New attribute (optional).
6262

63-
For add a label `ON` / `OFF`
63+
Will add the visual labels `ON/OFF`.
6464

6565
## Migration examples
6666

@@ -71,7 +71,7 @@ Checked toggle:
7171

7272
<!-- is now -->
7373

74-
<ods-toggle value>
74+
<ods-toggle value="true">
7575
</ods-toggle>
7676
```
7777

packages/storybook/stories/components/toggle/toggle.stories.ts

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,93 @@ const meta: Meta = {
1313
export default meta;
1414

1515
export const Demo: StoryObj = {
16+
render: (arg) => html`
17+
<ods-toggle class="my-toggle-demo"
18+
is-disabled=${arg.isDisabled}
19+
is-required=${arg.isRequired}
20+
with-label=${arg.withLabel}>
21+
</ods-toggle>
22+
<style>
23+
.my-toggle-demo::part(slider) {
24+
${arg.CustomCssSlider}
25+
}
26+
27+
.my-toggle-demo::part(slider)::before {
28+
${arg.CustomCssSlider}
29+
}
30+
31+
.my-toggle-demo::part(label) {
32+
${arg.CustomCssLabel}
33+
}
34+
35+
.my-toggle-demo::part(slider checked) {
36+
${arg.CustomCssSliderChecked}
37+
}
38+
39+
.my-toggle-demo::part(slider checked)::before {
40+
${arg.CustomCssSliderChecked}
41+
}
42+
43+
.my-toggle-demo::part(label checked) {
44+
${arg.CustomCssLabelChecked}
45+
}
46+
</style>
47+
`,
1648
argTypes: orderControls({
49+
CustomCssLabel: {
50+
control: 'text',
51+
description: 'Set a custom style properties for the label. Example: "color: green;"',
52+
table: {
53+
category: CONTROL_CATEGORY.design,
54+
defaultValue: { summary: 'ø' },
55+
type: { summary: 'string' },
56+
},
57+
},
58+
CustomCssLabelChecked: {
59+
control: 'text',
60+
description: 'Set a custom style properties for the label when the input is checked. Example: "color: black;"',
61+
table: {
62+
category: CONTROL_CATEGORY.design,
63+
defaultValue: { summary: 'ø' },
64+
type: { summary: 'string' },
65+
},
66+
},
67+
CustomCssSlider: {
68+
control: 'text',
69+
description: 'Set a custom style properties for the slider. Example: "background-color: red;"',
70+
table: {
71+
category: CONTROL_CATEGORY.design,
72+
defaultValue: { summary: 'ø' },
73+
type: { summary: 'string' },
74+
},
75+
},
76+
CustomCssSliderChecked: {
77+
control: 'text',
78+
description: 'Set a custom style properties for the slider when the input is checked. Example: "background-color: blueviolet;"',
79+
table: {
80+
category: CONTROL_CATEGORY.design,
81+
defaultValue: { summary: 'ø' },
82+
type: { summary: 'string' },
83+
},
84+
},
85+
CustomCssSliderCircle: {
86+
control: 'text',
87+
description: 'Set a custom style properties for the circle of the slider. Example: "background-color: blue;"',
88+
table: {
89+
category: CONTROL_CATEGORY.design,
90+
defaultValue: { summary: 'ø' },
91+
type: { summary: 'string' },
92+
},
93+
},
94+
CustomCssSliderCircleChecked: {
95+
control: 'text',
96+
description: 'Set a custom style properties for the circle of the slider when the input is checked. Example: "background-color: black;"',
97+
table: {
98+
category: CONTROL_CATEGORY.design,
99+
defaultValue: { summary: 'ø' },
100+
type: { summary: 'string' },
101+
},
102+
},
17103
isDisabled: {
18104
control: 'boolean',
19105
table: {
@@ -46,6 +132,39 @@ export const Demo: StoryObj = {
46132
},
47133
};
48134

135+
export const CustomCSS: StoryObj = {
136+
tags: ['isHidden'],
137+
render: () => html`
138+
<ods-toggle class="my-toggle" with-label>
139+
</ods-toggle>
140+
<style>
141+
.my-toggle::part(slider) {
142+
background-color: red;
143+
}
144+
145+
.my-toggle::part(slider)::before {
146+
background-color: blue;
147+
}
148+
149+
.my-toggle::part(label) {
150+
color: green;
151+
}
152+
153+
.my-toggle::part(slider checked) {
154+
background-color: blueviolet;
155+
}
156+
157+
.my-toggle::part(slider checked)::before {
158+
background-color: black;
159+
}
160+
161+
.my-toggle::part(label checked) {
162+
color: black;
163+
}
164+
</style>
165+
`,
166+
};
167+
49168
export const Default: StoryObj = {
50169
tags: ['isHidden'],
51170
render: () => html`

0 commit comments

Comments
 (0)