Skip to content

Commit a8611ca

Browse files
authored
chore(password generator, button): move demos to separate files (#12035)
1 parent 2be1496 commit a8611ca

File tree

4 files changed

+39
-38
lines changed

4 files changed

+39
-38
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
id: Button
3+
section: components
4+
---
5+
6+
import { useState } from 'react';
7+
import CheckCircleIcon from '@patternfly/react-icons/dist/esm/icons/check-circle-icon';
8+
9+
## Demos
10+
11+
### Progress button
12+
13+
The following demo shows the intended flow for a button that visually indicates progress. This example demonstrates a login process, which updates the button label based on the `loginState`.
14+
15+
Please note that only the button can be interacted with in this example. The username and password input fields cannot be edited as the focus is on the button behavior.
16+
17+
```ts file="./examples/ButtonProgress.tsx"
18+
19+
```

packages/react-core/src/demos/Button.md renamed to packages/react-core/src/demos/Button/examples/ButtonProgress.tsx

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,8 @@
1-
---
2-
id: Button
3-
section: components
4-
---
5-
6-
import { useState } from 'react';
7-
import CheckCircleIcon from '@patternfly/react-icons/dist/esm/icons/check-circle-icon';
8-
9-
## Demos
10-
11-
### Progress button
12-
13-
The following demo shows the intended flow for a button that visually indicates progress. This example demonstrates a login process, which updates the button label based on the `loginState`.
14-
15-
Please note that only the button can be interacted with in this example. The username and password input fields cannot be edited as the focus is on the button behavior.
16-
17-
```ts
181
import { useState } from 'react';
192
import { Form, FormGroup, ActionGroup, TextInput, Button } from '@patternfly/react-core';
203
import CheckCircleIcon from '@patternfly/react-icons/dist/esm/icons/check-circle-icon';
214

22-
const ProgressButton: React.FunctionComponent = () => {
5+
export const ButtonProgress: React.FunctionComponent = () => {
236
const [loginState, setLoginState] = useState<'notLoggedIn' | 'loading' | 'loggedIn'>('notLoggedIn');
247

258
return (
@@ -69,4 +52,3 @@ const ProgressButton: React.FunctionComponent = () => {
6952
</Form>
7053
);
7154
};
72-
```
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
id: Password generator
3+
section: patterns
4+
---
5+
6+
import { useEffect, useRef, useState } from 'react';
7+
import RedoIcon from '@patternfly/react-icons/dist/esm/icons/redo-icon';
8+
import EyeIcon from '@patternfly/react-icons/dist/esm/icons/eye-icon';
9+
import EyeSlashIcon from '@patternfly/react-icons/dist/esm/icons/eye-slash-icon';
10+
11+
## Demos
12+
13+
### Provide a generated password
14+
15+
```ts file="./examples/PasswordGenerator.tsx"
16+
```

packages/react-core/src/demos/PasswordGenerator.md renamed to packages/react-core/src/demos/PasswordGenerator/examples/PasswordGenerator.tsx

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
1-
---
2-
id: Password generator
3-
section: patterns
4-
---
5-
6-
import { useEffect, useRef, useState } from 'react';
7-
import RedoIcon from '@patternfly/react-icons/dist/esm/icons/redo-icon';
8-
import EyeIcon from '@patternfly/react-icons/dist/esm/icons/eye-icon';
9-
import EyeSlashIcon from '@patternfly/react-icons/dist/esm/icons/eye-slash-icon';
10-
11-
## Demos
12-
13-
### Provide a generated password
14-
15-
```ts
161
import { useEffect, useRef, useState } from 'react';
172
import {
183
InputGroup,
@@ -30,12 +15,12 @@ import RedoIcon from '@patternfly/react-icons/dist/esm/icons/redo-icon';
3015
import EyeIcon from '@patternfly/react-icons/dist/esm/icons/eye-icon';
3116
import EyeSlashIcon from '@patternfly/react-icons/dist/esm/icons/eye-slash-icon';
3217

33-
const PasswordGenerator: React.FunctionComponent = () => {
18+
export const PasswordGenerator: React.FunctionComponent = () => {
3419
const generatePassword = () => {
3520
const length = 12;
3621
const charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@%()_-=+';
3722
let retVal = '';
38-
for (var i = 0, n = charset.length; i < length; ++i) {
23+
for (let i = 0, n = charset.length; i < length; ++i) {
3924
retVal += charset.charAt(Math.floor(Math.random() * n));
4025
}
4126
return retVal;
@@ -153,7 +138,7 @@ const PasswordGenerator: React.FunctionComponent = () => {
153138
actions={
154139
<MenuItemAction
155140
icon={<RedoIcon />}
156-
onClick={(e) => {
141+
onClick={(_e) => {
157142
setGeneratedPassword(generatePassword());
158143
}}
159144
actionId="redo"
@@ -181,4 +166,3 @@ const PasswordGenerator: React.FunctionComponent = () => {
181166
/>
182167
);
183168
};
184-
```

0 commit comments

Comments
 (0)