You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add usage as controlled component to ViewSwitcher (#2240)
* feat(view-switcher): add uages as controlled component
* docs: mix up in type
* feat: warn if both props are passed
* docs: add comment about useState
* test: add test case for precedence
* docs: add changeset
* refactor(view-switcher): cleanup, generate readme, simplify test
* refactor: typo
Co-authored-by: Carlos Cortizas <[email protected]>
Co-authored-by: Nicola Molinari <[email protected]>
Co-authored-by: Carlos Cortizas <[email protected]>
<!-- THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -->
2
+
<!-- This file is created by the `yarn generate-readme` script. -->
3
+
1
4
# ViewSwitcher
2
5
3
6
## Description
4
7
5
-
ViewSwitchers allow users to toggle between two or more different views of the same, similar or related content items within the same space on screen.
8
+
The `<ViewSwitcher>` component allow users to toggle between two or more different views of the same, similar or related content items within the same space on screen.
6
9
7
10
## When to use
8
11
9
-
ViewSwitchers are frequently used to let users toggle between different formatting's, like with a grid view and a table view.
12
+
Let users toggle between different formatting's, like with a grid view and a table view.
10
13
11
14
## When not to use
12
15
13
-
Do not use the ViewSwitcher as Tabs
16
+
**Do not use the `<ViewSwitcher>` as tabs.**
14
17
Tabs should be used when the content on the page is divided into related sections but without any overlap.
15
-
See tabs as separate of content.
16
18
17
-
Do not use the ViewSwitcher as Toggle
18
-
Toggles are used for “yes/no” or “on/off” binary decisions.
19
+
**Do not use the `<ViewSwitcher>` as toggle.**
20
+
Toggles are used for "yes/no" or "on/off" binary decisions.
19
21
20
-
## Do's and Don'ts“
22
+
## Do's and Don'ts
21
23
22
-
- If you use an icon within the ViewSwitcher, each switch needs to have an icon.
23
-
- No colored icons are allowed. Only color-solid (black)
24
+
- If you use an icon within the `<ViewSwitcher>`, each switch needs to have an icon.
25
+
- No colored icons are allowed. Only `--color-solid` (black).
24
26
- Do not use two lines of text in one switch field.
|`isCondensed`|`boolean`||| Indicates that the view switcher can be reduced to save space |
74
-
|`children`|`ReactNode`| ✅ || Pass one or more `ViewSwitcher.Button` components |
75
-
|`onChange`|`Function`<br/>[See signature.](#signature-onChange)||| Will be triggered whenever a `ViewSwitcher.Button` is clicked. Called with the ViewSwitcherButton value |
76
-
|`defaultSelected`|`string`| ✅ || Indicates the default selected button |
|`isCondensed`|`boolean`||| Indicates that the view switcher can be reduced to save space. |
105
+
|`children`|`ReactNode`| ✅ || Pass one or more `ViewSwitcher.Button` components. |
106
+
|`onChange`|`Function`<br/>[See signature.](#signature-onChange)||| Will be triggered whenever a `ViewSwitcher.Button` is selected. Called with the ViewSwitcherButton value.
This function is only required when the component is controlled. |
107
+
|`defaultSelected`|`string`||| Passing this prop makes the component an uncontrolled component.
Indicates the default selected button it is only used to as an initial state once, when the component mounts. |
108
+
|`selectedValue`|`string`||| Passing this prop makes the component an controlled component.
Controlled components also require to pass a `onChange` callback function. |
The `<ViewSwitcher>` component allow users to toggle between two or more different views of the same, similar or related content items within the same space on screen.
2
+
3
+
## When to use
4
+
5
+
Let users toggle between different formatting's, like with a grid view and a table view.
6
+
7
+
## When not to use
8
+
9
+
**Do not use the `<ViewSwitcher>` as tabs.**
10
+
Tabs should be used when the content on the page is divided into related sections but without any overlap.
11
+
12
+
**Do not use the `<ViewSwitcher>` as toggle.**
13
+
Toggles are used for "yes/no" or "on/off" binary decisions.
14
+
15
+
## Do's and Don'ts
16
+
17
+
- If you use an icon within the `<ViewSwitcher>`, each switch needs to have an icon.
18
+
- No colored icons are allowed. Only `--color-solid` (black).
19
+
- Do not use two lines of text in one switch field.
'ui-kit/ViewSwitcher: passed both "selectedValue" (uncontrolled component) prop and "defaultSelected" (uncontrolled component). Please pass only one as the component can only be either controlled or uncontrolled.'
0 commit comments