@patternfly/react-core 4.227.7 → 4.227.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,177 +10,30 @@ ouia: true
10
10
 
11
11
  ### Basic
12
12
 
13
- ```js
14
- import React from 'react';
15
- import { Switch } from '@patternfly/react-core';
16
-
17
- class SimpleSwitch extends React.Component {
18
- constructor(props) {
19
- super(props);
20
- this.state = {
21
- isChecked: true
22
- };
23
- this.handleChange = isChecked => {
24
- this.setState({ isChecked });
25
- };
26
- }
27
-
28
- render() {
29
- const { isChecked } = this.state;
30
- return (
31
- <Switch
32
- id="simple-switch"
33
- label="Message when on"
34
- labelOff="Message when off"
35
- isChecked={isChecked}
36
- onChange={this.handleChange}
37
- />
38
- );
39
- }
40
- }
13
+ ```ts file="./SwitchBasic.tsx"
41
14
  ```
42
15
 
43
16
  ### Reversed Layout
44
17
 
45
- ```js
46
- import React from 'react';
47
- import { Switch } from '@patternfly/react-core';
48
-
49
- class ReversedSwitch extends React.Component {
50
- constructor(props) {
51
- super(props);
52
- this.state = {
53
- isChecked: true
54
- };
55
- this.handleChange = isChecked => {
56
- this.setState({ isChecked });
57
- };
58
- }
59
-
60
- render() {
61
- const { isChecked } = this.state;
62
- return (
63
- <Switch
64
- id="reversed-switch"
65
- label="Message when on"
66
- labelOff="Message when off"
67
- isChecked={isChecked}
68
- onChange={this.handleChange}
69
- isReversed
70
- />
71
- );
72
- }
73
- }
18
+ ```ts file="./SwitchReversed.tsx"
74
19
  ```
75
20
 
76
21
  ### Without label
77
22
 
78
- ```js
79
- import React from 'react';
80
- import { Switch } from '@patternfly/react-core';
81
-
82
- class NoLabelSwitch extends React.Component {
83
- constructor(props) {
84
- super(props);
85
- this.state = {
86
- isChecked: true
87
- };
88
- this.handleChange = isChecked => {
89
- this.setState({ isChecked });
90
- };
91
- }
92
-
93
- render() {
94
- const { isChecked } = this.state;
95
- return (
96
- <Switch id="no-label-switch-on" aria-label="Message when on" isChecked={isChecked} onChange={this.handleChange} />
97
- );
98
- }
99
- }
23
+ ```ts file="./SwitchWithoutLabel.tsx"
100
24
  ```
101
25
 
102
26
  ### Checked with label
103
27
 
104
- ```js
105
- import React from 'react';
106
- import { Switch } from '@patternfly/react-core';
107
-
108
- class CheckedWithLabelSwitch extends React.Component {
109
- constructor(props) {
110
- super(props);
111
- this.state = {
112
- isChecked: true
113
- };
114
- this.handleChange = isChecked => {
115
- this.setState({ isChecked });
116
- };
117
- }
118
-
119
- render() {
120
- const { isChecked } = this.state;
121
- return (
122
- <Switch
123
- label="Message when on"
124
- labelOff="Message when off"
125
- id="checked-with-label-switch-on"
126
- aria-label="Message when on"
127
- isChecked={isChecked}
128
- hasCheckIcon
129
- onChange={this.handleChange}
130
- />
131
- );
132
- }
133
- }
28
+ ```ts file="./SwitchCheckedWithLabel.tsx"
134
29
  ```
135
30
 
136
31
  ### Disabled
137
32
 
138
- ```js
139
- import React from 'react';
140
- import { Switch } from '@patternfly/react-core';
141
-
142
- <React.Fragment>
143
- <Switch
144
- id="disabled-switch-on"
145
- aria-label="Message when on"
146
- label="Message when on"
147
- labelOff="Message when off"
148
- isChecked
149
- isDisabled
150
- />
151
- <br />
152
- <Switch
153
- id="disabled-switch-off"
154
- aria-label="Message when on"
155
- label="Message when on"
156
- labelOff="Message when off"
157
- isChecked={false}
158
- isDisabled
159
- />
160
- <br />
161
- <Switch id="disabled-no-label-switch-on" aria-label="Message when on" isChecked isDisabled />
162
- <br />
163
- <Switch id="disabled-no-label-switch-off" aria-label="Message when on" isChecked={false} isDisabled />
164
- </React.Fragment>;
33
+ ```ts file="./SwitchDisabled.tsx"
165
34
  ```
166
35
 
167
36
  ### Uncontrolled
168
37
 
169
- ```js
170
- import React from 'react';
171
- import { Switch } from '@patternfly/react-core';
172
-
173
- <React.Fragment>
174
- <Switch
175
- id="uncontrolled-switch-no-label"
176
- aria-label="An uncontrolled switch with no label"
177
- defaultChecked={false}
178
- />
179
- <br />
180
- <Switch
181
- id="uncontrolled-switch-with-label"
182
- label="An uncontrolled switch"
183
- defaultChecked={false}
184
- />
185
- </React.Fragment>;
38
+ ```ts file="./SwitchUncontrolled.tsx"
186
39
  ```
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+ import { Switch } from '@patternfly/react-core';
3
+
4
+ export const SwitchBasic: React.FunctionComponent = () => {
5
+ const [isChecked, setIsChecked] = React.useState<boolean>(true);
6
+
7
+ const handleChange = (checked: boolean, _event: React.FormEvent<HTMLInputElement>) => {
8
+ setIsChecked(checked);
9
+ };
10
+
11
+ return (
12
+ <Switch
13
+ id="simple-switch"
14
+ label="Message when on"
15
+ labelOff="Message when off"
16
+ isChecked={isChecked}
17
+ onChange={handleChange}
18
+ />
19
+ );
20
+ };
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ import { Switch } from '@patternfly/react-core';
3
+
4
+ export const SwitchCheckedWithLabel: React.FunctionComponent = () => {
5
+ const [isChecked, setIsChecked] = React.useState<boolean>(true);
6
+
7
+ const handleChange = (checked: boolean, _event: React.FormEvent<HTMLInputElement>) => {
8
+ setIsChecked(checked);
9
+ };
10
+
11
+ return (
12
+ <Switch
13
+ label="Message when on"
14
+ labelOff="Message when off"
15
+ id="checked-with-label-switch-on"
16
+ aria-label="Message when on"
17
+ isChecked={isChecked}
18
+ hasCheckIcon
19
+ onChange={handleChange}
20
+ />
21
+ );
22
+ };
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+ import { Switch } from '@patternfly/react-core';
3
+
4
+ export const SwitchDisabled: React.FunctionComponent = () => (
5
+ <React.Fragment>
6
+ <Switch
7
+ id="disabled-switch-on"
8
+ aria-label="Message when on"
9
+ label="Message when on"
10
+ labelOff="Message when off"
11
+ isChecked
12
+ isDisabled
13
+ />
14
+ <br />
15
+ <Switch
16
+ id="disabled-switch-off"
17
+ aria-label="Message when on"
18
+ label="Message when on"
19
+ labelOff="Message when off"
20
+ isChecked={false}
21
+ isDisabled
22
+ />
23
+ <br />
24
+ <Switch id="disabled-no-label-switch-on" aria-label="Message when on" isChecked isDisabled />
25
+ <br />
26
+ <Switch id="disabled-no-label-switch-off" aria-label="Message when on" isChecked={false} isDisabled />
27
+ </React.Fragment>
28
+ );
@@ -0,0 +1,21 @@
1
+ import React from 'react';
2
+ import { Switch } from '@patternfly/react-core';
3
+
4
+ export const SwitchReversed: React.FunctionComponent = () => {
5
+ const [isChecked, setIsChecked] = React.useState<boolean>(true);
6
+
7
+ const handleChange = (checked: boolean, _event: React.FormEvent<HTMLInputElement>) => {
8
+ setIsChecked(checked);
9
+ };
10
+
11
+ return (
12
+ <Switch
13
+ id="reversed-switch"
14
+ label="Message when on"
15
+ labelOff="Message when off"
16
+ isChecked={isChecked}
17
+ onChange={handleChange}
18
+ isReversed
19
+ />
20
+ );
21
+ };
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import { Switch } from '@patternfly/react-core';
3
+
4
+ export const SwitchUncontrolled: React.FunctionComponent = () => (
5
+ <React.Fragment>
6
+ <Switch
7
+ id="uncontrolled-switch-no-label"
8
+ aria-label="An uncontrolled switch with no label"
9
+ defaultChecked={false}
10
+ />
11
+ <br />
12
+ <Switch id="uncontrolled-switch-with-label" label="An uncontrolled switch" defaultChecked={false} />
13
+ </React.Fragment>
14
+ );
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import { Switch } from '@patternfly/react-core';
3
+
4
+ export const SwitchWithoutLabel: React.FunctionComponent = () => {
5
+ const [isChecked, setIsChecked] = React.useState<boolean>(true);
6
+
7
+ const handleChange = (checked: boolean, _event: React.FormEvent<HTMLInputElement>) => {
8
+ setIsChecked(checked);
9
+ };
10
+
11
+ return <Switch id="no-label-switch-on" aria-label="Message when on" isChecked={isChecked} onChange={handleChange} />;
12
+ };