@indico-data/design-system 2.6.0 → 2.8.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 +165 -0
- package/lib/index.d.ts +26 -2
- package/lib/index.esm.css +165 -0
- package/lib/index.esm.js +11 -1
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +12 -0
- package/lib/index.js.map +1 -1
- package/lib/src/components/forms/checkbox/Checkbox.d.ts +12 -0
- package/lib/src/components/forms/checkbox/Checkbox.stories.d.ts +7 -0
- package/lib/src/components/forms/checkbox/__tests__/Checkbox.test.d.ts +1 -0
- package/lib/src/components/forms/checkbox/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 +2 -0
- package/lib/src/index.d.ts +2 -0
- package/package.json +1 -1
- package/src/components/forms/checkbox/Checkbox.mdx +72 -0
- package/src/components/forms/checkbox/Checkbox.stories.tsx +175 -0
- package/src/components/forms/checkbox/Checkbox.tsx +55 -0
- package/src/components/forms/checkbox/__tests__/Checkbox.test.tsx +35 -0
- package/src/components/forms/checkbox/index.ts +1 -0
- package/src/components/forms/checkbox/styles/Checkbox.scss +98 -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 +2 -0
- package/src/index.ts +2 -0
- package/src/styles/index.scss +2 -0
|
@@ -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
|
@@ -63,3 +63,5 @@ export { Icon } from './components/icons';
|
|
|
63
63
|
export { Table } from './components/table';
|
|
64
64
|
export { Input } from './components/forms/input';
|
|
65
65
|
export { Radio as RadioInput } from './components/forms/radio';
|
|
66
|
+
export { Checkbox } from './components/forms/checkbox';
|
|
67
|
+
export { Toggle as ToggleInput } from './components/forms/toggle';
|
package/src/styles/index.scss
CHANGED
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
@import '../components/table/styles/Table.scss';
|
|
9
9
|
@import '../components/forms/input/styles/Input.scss';
|
|
10
10
|
@import '../components/forms/radio/styles/Radio.scss';
|
|
11
|
+
@import '../components/forms/checkbox/styles/Checkbox.scss';
|
|
11
12
|
|
|
13
|
+
@import '../components/forms/toggle/styles/Toggle.scss';
|
|
12
14
|
@import 'typography';
|
|
13
15
|
@import 'colors';
|
|
14
16
|
@import 'borders';
|