@indico-data/design-system 2.7.0 → 2.9.0
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.
- package/lib/index.css +195 -19
- package/lib/index.d.ts +14 -2
- package/lib/index.esm.css +195 -19
- package/lib/index.esm.js +7 -2
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +7 -1
- package/lib/index.js.map +1 -1
- package/lib/src/components/forms/textarea/Textarea.d.ts +22 -0
- package/lib/src/components/forms/textarea/Textarea.stories.d.ts +11 -0
- package/lib/src/components/forms/textarea/__tests__/Textarea.test.d.ts +1 -0
- package/lib/src/components/forms/textarea/index.d.ts +1 -0
- package/lib/src/components/forms/toggle/Toggle.d.ts +12 -0
- package/lib/src/components/forms/toggle/Toggle.stories.d.ts +6 -0
- package/lib/src/components/forms/toggle/__tests__/Toggle.test.d.ts +1 -0
- package/lib/src/components/forms/toggle/index.d.ts +1 -0
- package/lib/src/components/index.d.ts +1 -0
- package/lib/src/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/components/forms/checkbox/Checkbox.mdx +6 -1
- package/src/components/forms/checkbox/Checkbox.stories.tsx +10 -4
- package/src/components/forms/checkbox/Checkbox.tsx +1 -1
- package/src/components/forms/checkbox/styles/Checkbox.scss +16 -16
- package/src/components/forms/input/Input.stories.tsx +70 -64
- package/src/components/forms/input/styles/Input.scss +10 -3
- package/src/components/forms/textarea/Textarea.mdx +19 -0
- package/src/components/forms/textarea/Textarea.stories.tsx +363 -0
- package/src/components/forms/textarea/Textarea.tsx +85 -0
- package/src/components/forms/textarea/__tests__/Textarea.test.tsx +103 -0
- package/src/components/forms/textarea/index.ts +1 -0
- package/src/components/forms/textarea/styles/Textarea.scss +102 -0
- package/src/components/forms/toggle/Toggle.mdx +15 -0
- package/src/components/forms/toggle/Toggle.stories.tsx +126 -0
- package/src/components/forms/toggle/Toggle.tsx +51 -0
- package/src/components/forms/toggle/__tests__/Toggle.test.tsx +19 -0
- package/src/components/forms/toggle/index.ts +1 -0
- package/src/components/forms/toggle/styles/Toggle.scss +72 -0
- package/src/components/index.ts +1 -0
- package/src/index.ts +1 -0
- package/src/styles/index.scss +2 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { Toggle } from './Toggle';
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
|
|
5
|
+
const meta: Meta = {
|
|
6
|
+
title: 'Forms/Toggle',
|
|
7
|
+
component: Toggle,
|
|
8
|
+
argTypes: {
|
|
9
|
+
isChecked: {
|
|
10
|
+
control: false,
|
|
11
|
+
description: 'This is the state of the toggle',
|
|
12
|
+
table: {
|
|
13
|
+
category: 'Props',
|
|
14
|
+
type: {
|
|
15
|
+
summary: 'boolean',
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
defaultValue: { summary: false },
|
|
19
|
+
},
|
|
20
|
+
ref: {
|
|
21
|
+
table: {
|
|
22
|
+
disable: true,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
onChange: {
|
|
26
|
+
control: false,
|
|
27
|
+
description: 'onChange event handler',
|
|
28
|
+
table: {
|
|
29
|
+
category: 'Callbacks',
|
|
30
|
+
type: {
|
|
31
|
+
summary: '(e: React.ChangeEvent<HTMLInputElement>) => void',
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
action: 'onChange',
|
|
35
|
+
},
|
|
36
|
+
label: {
|
|
37
|
+
control: 'text',
|
|
38
|
+
description: 'The label for the toggle field',
|
|
39
|
+
table: {
|
|
40
|
+
category: 'Props',
|
|
41
|
+
type: {
|
|
42
|
+
summary: 'string',
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
defaultValue: { summary: '' },
|
|
46
|
+
},
|
|
47
|
+
name: {
|
|
48
|
+
control: 'text',
|
|
49
|
+
description: 'The name for the toggle field',
|
|
50
|
+
table: {
|
|
51
|
+
category: 'Props',
|
|
52
|
+
type: {
|
|
53
|
+
summary: 'string',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
defaultValue: { summary: '' },
|
|
57
|
+
},
|
|
58
|
+
value: {
|
|
59
|
+
control: 'text',
|
|
60
|
+
description: 'This holds the value that will be emitted when the toggle is selected',
|
|
61
|
+
table: {
|
|
62
|
+
category: 'Props',
|
|
63
|
+
type: {
|
|
64
|
+
summary: 'string',
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
defaultValue: { summary: '' },
|
|
68
|
+
},
|
|
69
|
+
id: {
|
|
70
|
+
control: 'text',
|
|
71
|
+
description: 'This explains what button group this toggle belongs to.',
|
|
72
|
+
table: {
|
|
73
|
+
category: 'Props',
|
|
74
|
+
type: {
|
|
75
|
+
summary: 'string',
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
defaultValue: { summary: '' },
|
|
79
|
+
},
|
|
80
|
+
isDisabled: {
|
|
81
|
+
control: 'boolean',
|
|
82
|
+
description: 'This disables the toggle',
|
|
83
|
+
table: {
|
|
84
|
+
category: 'Props',
|
|
85
|
+
type: {
|
|
86
|
+
summary: 'boolean',
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
defaultValue: { summary: false },
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export default meta;
|
|
95
|
+
|
|
96
|
+
type Story = StoryObj<typeof Toggle>;
|
|
97
|
+
|
|
98
|
+
export const Default: Story = {
|
|
99
|
+
args: {
|
|
100
|
+
id: 'toggle',
|
|
101
|
+
label: 'switch label',
|
|
102
|
+
isDisabled: false,
|
|
103
|
+
name: 'toggle',
|
|
104
|
+
value: 'toggle',
|
|
105
|
+
isChecked: false,
|
|
106
|
+
},
|
|
107
|
+
render: (args) => {
|
|
108
|
+
const [checkedValue, setCheckedValue] = useState<boolean>(false);
|
|
109
|
+
|
|
110
|
+
const handleChange = () => {
|
|
111
|
+
setCheckedValue(!checkedValue);
|
|
112
|
+
};
|
|
113
|
+
return (
|
|
114
|
+
<Toggle
|
|
115
|
+
key={args.id}
|
|
116
|
+
onChange={handleChange}
|
|
117
|
+
id={args.id}
|
|
118
|
+
label={args.label}
|
|
119
|
+
name={args.name}
|
|
120
|
+
value={args.value}
|
|
121
|
+
isDisabled={args.isDisabled}
|
|
122
|
+
isChecked={checkedValue}
|
|
123
|
+
/>
|
|
124
|
+
);
|
|
125
|
+
},
|
|
126
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
export interface ToggleProps {
|
|
4
|
+
ref?: React.LegacyRef<HTMLInputElement>;
|
|
5
|
+
id: string;
|
|
6
|
+
label?: string;
|
|
7
|
+
name: string;
|
|
8
|
+
value?: string;
|
|
9
|
+
onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
|
10
|
+
isDisabled?: boolean;
|
|
11
|
+
isChecked?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const Toggle = ({
|
|
15
|
+
ref,
|
|
16
|
+
id,
|
|
17
|
+
label,
|
|
18
|
+
name,
|
|
19
|
+
value,
|
|
20
|
+
onChange,
|
|
21
|
+
isDisabled,
|
|
22
|
+
isChecked,
|
|
23
|
+
...rest
|
|
24
|
+
}: ToggleProps) => {
|
|
25
|
+
return (
|
|
26
|
+
<div className="form-control">
|
|
27
|
+
<div className="toggle-wrapper">
|
|
28
|
+
<input
|
|
29
|
+
data-testid={`form-toggle-input-${name}`}
|
|
30
|
+
className="toggle-input"
|
|
31
|
+
type="checkbox"
|
|
32
|
+
id={id}
|
|
33
|
+
checked={isChecked}
|
|
34
|
+
name={name}
|
|
35
|
+
value={value}
|
|
36
|
+
disabled={isDisabled}
|
|
37
|
+
ref={ref}
|
|
38
|
+
onChange={onChange}
|
|
39
|
+
tabIndex={0}
|
|
40
|
+
aria-describedby={id}
|
|
41
|
+
aria-label={label}
|
|
42
|
+
{...rest}
|
|
43
|
+
/>
|
|
44
|
+
<label htmlFor={id} className="switch"></label>
|
|
45
|
+
<label className={'toggle-label'} htmlFor={id}>
|
|
46
|
+
{label}
|
|
47
|
+
</label>
|
|
48
|
+
</div>
|
|
49
|
+
</div>
|
|
50
|
+
);
|
|
51
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { render, screen, act } from '@testing-library/react';
|
|
2
|
+
import { Toggle } from '@/components/forms/toggle/Toggle';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
|
|
5
|
+
const handleOnChange = jest.fn();
|
|
6
|
+
|
|
7
|
+
describe('Toggle', () => {
|
|
8
|
+
it('renders the Toggle input field', () => {
|
|
9
|
+
render(<Toggle label="Option 1" name="name" onChange={handleOnChange} id={'ButtonGroup'} />);
|
|
10
|
+
expect(screen.getByLabelText('Option 1')).toBeInTheDocument();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('calls the onChange function when the Toggle input is clicked', async () => {
|
|
14
|
+
render(<Toggle label="Option 1" name="name" onChange={handleOnChange} id={'ButtonGroup'} />);
|
|
15
|
+
expect(handleOnChange).toHaveBeenCalledTimes(0);
|
|
16
|
+
await userEvent.click(screen.getByLabelText('Option 1'));
|
|
17
|
+
expect(handleOnChange).toHaveBeenCalledTimes(1);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Toggle } from './Toggle';
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// Common Variables
|
|
2
|
+
:root,
|
|
3
|
+
:root [data-theme='light'],
|
|
4
|
+
:root [data-theme='dark'] {
|
|
5
|
+
--pf-toggle-background-color: var(--pf-gray-color-200);
|
|
6
|
+
--pf-toggle-circle-color: var(--pf-primary-color);
|
|
7
|
+
--pf-toggle-border-color: var(--pf-gray-color);
|
|
8
|
+
--pf-toggle-disabled-background-color: var(--pf-gray-color-400);
|
|
9
|
+
--pf-toggle-disabled-circle-color: var(--pf-gray-color-300);
|
|
10
|
+
--pf-toggle-checked-background-color: var(--pf-primary-color-200);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Dark Theme Specific Variables
|
|
14
|
+
:root [data-theme='dark'] {
|
|
15
|
+
--pf-toggle-background-color: var(--pf-primary-color-100);
|
|
16
|
+
--pf-toggle-circle-color: var(--pf-white-color);
|
|
17
|
+
--pf-toggle-border-color: var(--pf-white-color);
|
|
18
|
+
--pf-toggle-disabled-background-color: var(--pf-gray-color-600);
|
|
19
|
+
--pf-toggle-disabled-circle-color: var(--pf-gray-color-900);
|
|
20
|
+
--pf-toggle-checked-background-color: var(--pf-secondary-color-400);
|
|
21
|
+
}
|
|
22
|
+
.switch {
|
|
23
|
+
position: relative;
|
|
24
|
+
display: inline-block;
|
|
25
|
+
width: 40px;
|
|
26
|
+
height: 20px;
|
|
27
|
+
background-color: var(--pf-toggle-background-color);
|
|
28
|
+
border-radius: 20px;
|
|
29
|
+
transition: all 0.3s;
|
|
30
|
+
cursor: pointer;
|
|
31
|
+
}
|
|
32
|
+
.switch::after {
|
|
33
|
+
content: '';
|
|
34
|
+
position: absolute;
|
|
35
|
+
width: 18px;
|
|
36
|
+
height: 18px;
|
|
37
|
+
border-radius: 50%;
|
|
38
|
+
background-color: var(--pf-toggle-circle-color);
|
|
39
|
+
top: 1px;
|
|
40
|
+
left: 1px;
|
|
41
|
+
transition: all 0.3s;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.toggle-input:checked + label.switch::after {
|
|
45
|
+
left: 20px;
|
|
46
|
+
}
|
|
47
|
+
.toggle-input:checked + label.switch {
|
|
48
|
+
background-color: var(--pf-toggle-checked-background-color);
|
|
49
|
+
}
|
|
50
|
+
.toggle-input:checked,
|
|
51
|
+
.toggle-input:not(:checked) {
|
|
52
|
+
position: absolute;
|
|
53
|
+
left: -9999px;
|
|
54
|
+
}
|
|
55
|
+
.toggle-input:disabled + label.switch {
|
|
56
|
+
background-color: var(--pf-toggle-disabled-background-color);
|
|
57
|
+
cursor: not-allowed;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.toggle-input:disabled + label.switch::after {
|
|
61
|
+
background-color: var(--pf-toggle-disabled-circle-color);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.toggle-wrapper {
|
|
65
|
+
display: flex;
|
|
66
|
+
align-items: center;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.toggle-label {
|
|
70
|
+
cursor: pointer;
|
|
71
|
+
margin-left: var(--pf-margin-2);
|
|
72
|
+
}
|
package/src/components/index.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -64,3 +64,4 @@ export { Table } from './components/table';
|
|
|
64
64
|
export { Input } from './components/forms/input';
|
|
65
65
|
export { Radio as RadioInput } from './components/forms/radio';
|
|
66
66
|
export { Checkbox } from './components/forms/checkbox';
|
|
67
|
+
export { Toggle as ToggleInput } from './components/forms/toggle';
|
package/src/styles/index.scss
CHANGED
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
@import '../components/forms/input/styles/Input.scss';
|
|
10
10
|
@import '../components/forms/radio/styles/Radio.scss';
|
|
11
11
|
@import '../components/forms/checkbox/styles/Checkbox.scss';
|
|
12
|
+
@import '../components/forms/textarea/styles/Textarea.scss';
|
|
12
13
|
|
|
14
|
+
@import '../components/forms/toggle/styles/Toggle.scss';
|
|
13
15
|
@import 'typography';
|
|
14
16
|
@import 'colors';
|
|
15
17
|
@import 'borders';
|