Skip to content

Commit d807f25

Browse files
authored
Merge pull request #492 from dxc-technology/component-switch
Component switch documentation update
2 parents 35aa131 + 486f8e0 commit d807f25

File tree

11 files changed

+69
-57
lines changed

11 files changed

+69
-57
lines changed
55.2 KB
Binary file not shown.

guidelines/components/switch/README.md

Lines changed: 69 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,73 +3,93 @@
33
Switch toggles are elements that can get two simple states, each of them has an impact on the system and it can be switched on or off, there are no more options.
44
If the switch toggle is on one state, the action to change it will modify to value of the element to the contrary.
55

6-
The main difference to using a switch toggle instead of other components with a similar purpose like radio buttons or checkboxes are the immediate effect that they should take. This grants the users control on the application, changing preferences and configuration settings.
6+
## Usage
77

8-
With the use of switch toggle, it is not needed a submit button to do the appropriate action, because the action takes place at the moment that the switch is turned on or off.
8+
- Switch toggles should be used in place of radio buttons whenever the options are opposites of each other (i.e. yes/no, on/off, etc).
9+
- Whenever is possible stack the switch component vertically.
10+
- Switches have immediate effect over the application, changing preferences and configuration settings. Don't use a submit button.
11+
12+
## States
913

10-
## Appereance
14+
Five different states are defined in the life cycle of the component: **unselected enabled**, **unselected focus**, **unselected disabled**, **selected enabled**, **selected focus** and **selected disabled**
1115

12-
The appearance of the component should provide good visual feedback, making clear when the switch is on or off. To make a difference between states colors, shadows and fill properties can be used.
16+
![Switch component states](images/switch_states.png)
1317

14-
A label can be linked with the component to indicate what action will perform when the change occurs. It should be descriptive and clear about what the component is doing or affecting.
18+
_Switch component states_
1519

16-
## Modes
20+
## Anatomy
1721

18-
Two main modes are represented within the component.
22+
![Switch component anatomy](images/switch_anatomy.png)
1923

20-
Modes: **on** and **off**.
24+
1. Label
25+
2. Thumb
26+
3. Track
2127

22-
![Switch modes](images/switch_modes.png)
28+
## Stacking
2329

24-
## States
30+
![Switch stacking options](images/switch_stacking.png)
31+
32+
_Switch stacking options_
33+
34+
In some application the use of several switches based on the requirements could appear, that why we provide some indications in the case that the user needs to use stacked switches.
35+
36+
## Label position
2537

26-
Five different states are defined in the life cycle of the component: **normal**, **disabled**, **hovered** and **focused**.
38+
![Switch label position options example](images/switch_label_position.png)
2739

28-
![Switch modes](images/switch_states.png)
40+
_Switch label position options example_
2941

30-
## Design tokens
42+
| Position | Description |
43+
| :--------------- | :-------------------------------------------------------- |
44+
| **Label before** | Labels before the switch indicate what the switch is for |
45+
| **Label after** | Labels after the switch indicate the state of the switch |
3146

32-
| Tokens | Default value |
33-
| ------------------------------------- | ------------: |
34-
| `checkedTrackBackgroundColor` | #5f249f |
35-
| `disabledCheckedTrackBackgroundColor` | #D0BDDB |
36-
| `checkedthumbBackgroundColor` | #FFFFFF |
37-
| `uncheckedThumbBackgroundColor` | #FFFFFF |
38-
| `uncheckedTrackBackgroundColor` | #D9D9D9 |
39-
| `disabledUncheckedTrackBackgroundColor` | #D9D9D9 + 0.12 opacity |
40-
| `fontColor` | #000000 |
41-
| `disabledFontColor` | #000000 + 0.12 opacity |
42-
| `focusColor` | #005FCC |
4347

4448
## Design Specifications
4549

46-
Schematics examples for the switch toggle component with all the variations.
4750

48-
![Switch specifications](images/switch_specs.png)
51+
![Switch design specifications](images/switch_specs.png)
4952

50-
In some application the use of several switches based on the requirments could appear, that why we provide some indications in the case that the user needs to use stacked or linear switches.
53+
_Switch design specifications_
5154

52-
### Linear
5355

54-
The text should have a margin of 16 pixels based on its position. If the text is after the switch, it should define the margin on the right side. Otherwise, if the label of the switch is before the component, the margin has to go on the left side.
56+
### Color
5557

56-
![Switch linear structure](images/switch_linear.png)
58+
| Component token | Element | Core token | Value |
59+
| :---------------------------------------- | :------------------------------ | :------------------ | :-------- |
60+
| `labelFontColor` | Label | `color-black` | #000000 |
61+
| `disabledLabelFontColor` | Label:disabled | `color-grey-400` | #bfbfbf |
62+
| `thumbBackgroundColor` | Thumb | `color-white` | #ffffff |
63+
| `focusThumbBorderColor` | Thumb:focus | `color-blue-600` | #0095ff |
64+
| `unselectedTrackBackgroundColor` | Track unselected | `color-grey-400` | #bfbfbf |
65+
| `selectedTrackBackgroundColor` | Track selected | `color-purple-700` | #5f249f |
66+
| `disableudUnselectedTrackBackgroundColor` | Track:disabled unselected | `color-grey-100` | #f2f2f2 |
67+
| `disabledSelectedTrackBackgroundColor` | Track:disabled selected | `color-purple-100` | #f2eafa |
5768

58-
### Stacked
5969

60-
The spacing between stacked switches should be 24 pixels that is determining by the top/bottom margin of the switch component itself.
70+
### Typography
6171

62-
![Switch stacked structure](images/switch_stacked.png)
72+
| Component token | Element | Core token | Value |
73+
| :---------------------------------------- | :------------------------------ | :-------------------- | :----------- |
74+
| `labelFontFamily` | Label | `font-family-sans` | Open sans |
75+
| `labelFontSize` | Label | `font-scale-02` | 1rem / 16px |
76+
| `labelFontWeight` | Label | `font-weight-regular` | 400 |
77+
| `labelFontStyle` | Label | `font-style-normal` | normal |
6378

64-
#### Sizes
6579

66-
| Property | Value |
67-
| -------------------------- | ------------: |
68-
| Toggle bar | 36px |
69-
| Focused ripple | 42x42px |
70-
| Toggle button | 24x24px |
80+
### Size
7181

72-
#### Margin
82+
| Component token | Element | Core token | Value |
83+
| :---------------------------------------- | :------------------------------ | :-------------------- | :----------- |
84+
| `thumbHeight` | Thumb | - | 24px |
85+
| `thumbWidth` | Thumb | - | 24px |
86+
| `trackHeight` | Track | - | 12px |
87+
| `trackWidth` | Track | - | 60px |
88+
| `focusHeight` | Focus indicator | - | 40px |
89+
| `focusWidth` | Focus indicator | - | 40px |
90+
91+
92+
### Margin
7393

7494
margin | value
7595
-- | --
@@ -84,29 +104,21 @@ margin | value
84104
And also apply different values to each side of the component:
85105
`top` `bottom` `left` `right`
86106

87-
#### Typography
88-
89-
| Property | Value |
90-
| -------------------------- | ------------: |
91-
| Font size (with text) | `16px` |
92-
| Font weight | `Regular` |
93-
94-
#### Spacing
95107

96-
| Property | Value |
97-
| -------------------------- | ------------: |
98-
| Spacing between label and toggle | `12px` |
108+
### Spacing
99109

110+
| Property | Element | Core token | Value |
111+
| :------------------------ | :------------------------------ | :-------------------- | :------------------- |
112+
| `padding` | Thumb | `spacing-03` | 0.5rem / 8px |
113+
| `margin-left/right`* | Switch | `spacing-03` | 0.5rem / 8px |
114+
| `padding` | Track | `spacing-04` | 0.75rem / 12px |
100115

101-
102-
## User Interface Design Considerations
103-
104-
- Switch toggles should be used in place of radio buttons whenever the options are opposites of each other (i.e. yes/no, on/off, etc).
105-
- Try to present your lists vertically, with one choice per line.
116+
_*Depending of the position of the label_
106117

107118
## Links and references
108119

109-
- https://xd.adobe.com/view/23e2cca4-5021-490a-a548-e99a9b4a2006-76b1/screen/c3026d48-f954-4978-91e4-05d323ee078c/variables/
120+
- [React CDK component](https://developer.dxc.com/tools/react/next/#/components/switch)
121+
- [Angular CDK component](https://developer.dxc.com/tools/angular/next/#/components/switch)
110122

111123
____________________________________________________________
112124

9.03 KB
Loading
11.3 KB
Loading
-8.39 KB
Binary file not shown.
-8.21 KB
Binary file not shown.
12.5 KB
Loading
-11.3 KB
Binary file not shown.
26 KB
Loading
4.99 KB
Loading

0 commit comments

Comments
 (0)