@indico-data/design-system 1.0.54 → 1.0.56
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/components/Toggle/Toggle.d.ts +12 -0
- package/lib/components/Toggle/Toggle.stories.d.ts +21 -0
- package/lib/components/Toggle/Toggle.styles.d.ts +2 -0
- package/lib/components/Toggle/index.d.ts +1 -0
- package/lib/components/Tooltip/Tooltip.d.ts +15 -0
- package/lib/components/Tooltip/Tooltip.stories.d.ts +9 -0
- package/lib/components/Tooltip/Tooltip.styles.d.ts +2 -0
- package/lib/components/Tooltip/index.d.ts +1 -0
- package/lib/components/containment/Tooltip/Tooltip.d.ts +15 -0
- package/lib/components/containment/Tooltip/Tooltip.stories.d.ts +6 -0
- package/lib/components/containment/Tooltip/Tooltip.styles.d.ts +2 -0
- package/lib/components/containment/Tooltip/index.d.ts +1 -0
- package/lib/components/index.d.ts +1 -0
- package/lib/index.d.ts +154 -57
- package/lib/index.esm.js +292 -1
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +295 -0
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Toggle/Toggle.stories.tsx +56 -0
- package/src/components/Toggle/Toggle.styles.ts +86 -0
- package/src/components/Toggle/Toggle.tsx +57 -0
- package/src/components/Toggle/index.ts +1 -0
- package/src/components/index.ts +1 -0
- package/src/index.ts +3 -0
package/package.json
CHANGED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
3
|
+
|
|
4
|
+
import { Toggle } from './Toggle';
|
|
5
|
+
|
|
6
|
+
const meta = {
|
|
7
|
+
component: Toggle,
|
|
8
|
+
title: 'Toggle',
|
|
9
|
+
argTypes: {},
|
|
10
|
+
args: {},
|
|
11
|
+
} satisfies Meta<typeof Toggle>;
|
|
12
|
+
|
|
13
|
+
export default meta;
|
|
14
|
+
type Story = StoryObj<typeof Toggle>;
|
|
15
|
+
|
|
16
|
+
function StoryRender(props: any) {
|
|
17
|
+
const [isPressed, setIsPressed] = useState(false);
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<Toggle
|
|
21
|
+
{...props}
|
|
22
|
+
value={isPressed}
|
|
23
|
+
onChange={() => {
|
|
24
|
+
console.log(isPressed);
|
|
25
|
+
setIsPressed(!isPressed);
|
|
26
|
+
}}
|
|
27
|
+
disabled={props.disabled}
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const Normal: Story = {
|
|
33
|
+
args: {},
|
|
34
|
+
render: (args) => {
|
|
35
|
+
return <StoryRender {...args} />;
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const Disabled: Story = {
|
|
40
|
+
args: {
|
|
41
|
+
disabled: true,
|
|
42
|
+
},
|
|
43
|
+
render: (args) => {
|
|
44
|
+
return <StoryRender {...args} />;
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const Icons: Story = {
|
|
49
|
+
args: {
|
|
50
|
+
checkedIconName: 'fa-check',
|
|
51
|
+
notCheckedIconName: 'x-close',
|
|
52
|
+
},
|
|
53
|
+
render: (args) => {
|
|
54
|
+
return <StoryRender {...args} />;
|
|
55
|
+
},
|
|
56
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
|
|
3
|
+
import { COLORS } from '@/tokens';
|
|
4
|
+
|
|
5
|
+
export const StyledToggle = styled.label`
|
|
6
|
+
position: relative;
|
|
7
|
+
display: inline-block;
|
|
8
|
+
width: 28px;
|
|
9
|
+
height: 18px;
|
|
10
|
+
border: 2px solid ${COLORS.defaultFontColor};
|
|
11
|
+
border-radius: 34px;
|
|
12
|
+
margin-bottom: 0;
|
|
13
|
+
cursor: pointer;
|
|
14
|
+
|
|
15
|
+
& input {
|
|
16
|
+
display: none;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
&.disabled {
|
|
20
|
+
cursor: not-allowed;
|
|
21
|
+
opacity: 0.5;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.slider {
|
|
25
|
+
position: absolute;
|
|
26
|
+
top: 0;
|
|
27
|
+
left: -1px;
|
|
28
|
+
right: 0;
|
|
29
|
+
bottom: 0;
|
|
30
|
+
transition: 0.4s;
|
|
31
|
+
border-radius: 34px;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.slider:before {
|
|
35
|
+
position: absolute;
|
|
36
|
+
content: '';
|
|
37
|
+
height: 17px;
|
|
38
|
+
width: 17px;
|
|
39
|
+
left: -1px;
|
|
40
|
+
bottom: -1px;
|
|
41
|
+
background-color: ${COLORS.clay};
|
|
42
|
+
transition: 0.4s;
|
|
43
|
+
border: 2px solid ${COLORS.defaultFontColor};
|
|
44
|
+
border-radius: 50%;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
input:checked + .slider {
|
|
48
|
+
background-color: ${COLORS.defaultFontColor};
|
|
49
|
+
width: 100%;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
input:checked + .slider:before {
|
|
53
|
+
transform: translateX(12px);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
p {
|
|
57
|
+
position: relative;
|
|
58
|
+
left: 35px;
|
|
59
|
+
bottom: 2px;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.checked-icon,
|
|
63
|
+
.not-checked-icon {
|
|
64
|
+
position: absolute;
|
|
65
|
+
pointer-events: none;
|
|
66
|
+
top: 50%;
|
|
67
|
+
transform: translateY(-50%);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.checked-icon {
|
|
71
|
+
fill: #fff;
|
|
72
|
+
display: none;
|
|
73
|
+
left: 3px;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.not-checked-icon {
|
|
77
|
+
right: 3px;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
input:checked ~ .not-checked-icon {
|
|
81
|
+
display: none;
|
|
82
|
+
}
|
|
83
|
+
input:checked ~ .checked-icon {
|
|
84
|
+
display: block;
|
|
85
|
+
}
|
|
86
|
+
`;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// TODO: This component's migration was fast-tracked for Insights. Assess for potential refactor and documentation.
|
|
2
|
+
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import classNames from 'classnames';
|
|
5
|
+
|
|
6
|
+
import { Icon } from '@/components';
|
|
7
|
+
import { PermafrostComponent, IconName } from '@/types';
|
|
8
|
+
import { StyledToggle } from './Toggle.styles';
|
|
9
|
+
|
|
10
|
+
type Props = {
|
|
11
|
+
disabled: boolean;
|
|
12
|
+
onChange: any;
|
|
13
|
+
value: boolean;
|
|
14
|
+
['aria-label']?: string;
|
|
15
|
+
iconSize?: number | string;
|
|
16
|
+
checkedIconName?: IconName;
|
|
17
|
+
notCheckedIconName?: IconName;
|
|
18
|
+
} & PermafrostComponent;
|
|
19
|
+
|
|
20
|
+
export const Toggle = (props: Props) => {
|
|
21
|
+
const {
|
|
22
|
+
disabled,
|
|
23
|
+
onChange,
|
|
24
|
+
value,
|
|
25
|
+
className,
|
|
26
|
+
id,
|
|
27
|
+
checkedIconName,
|
|
28
|
+
notCheckedIconName,
|
|
29
|
+
iconSize,
|
|
30
|
+
} = props;
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<StyledToggle
|
|
34
|
+
className={classNames(className, {
|
|
35
|
+
disabled,
|
|
36
|
+
})}
|
|
37
|
+
data-cy={props['data-cy']}
|
|
38
|
+
id={id}
|
|
39
|
+
>
|
|
40
|
+
<input
|
|
41
|
+
aria-label={props['aria-label']}
|
|
42
|
+
type="checkbox"
|
|
43
|
+
disabled={disabled}
|
|
44
|
+
checked={value}
|
|
45
|
+
onChange={onChange}
|
|
46
|
+
/>
|
|
47
|
+
<span className="slider round" />
|
|
48
|
+
|
|
49
|
+
{checkedIconName && (
|
|
50
|
+
<Icon name={checkedIconName} size={[iconSize || 5]} className="checked-icon" />
|
|
51
|
+
)}
|
|
52
|
+
{notCheckedIconName && (
|
|
53
|
+
<Icon name={notCheckedIconName} size={[iconSize || 5]} className="not-checked-icon" />
|
|
54
|
+
)}
|
|
55
|
+
</StyledToggle>
|
|
56
|
+
);
|
|
57
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Toggle } from './Toggle';
|
package/src/components/index.ts
CHANGED
|
@@ -33,3 +33,4 @@ export { Wizard, WizardCard, WizardSection, StyledWizard } from './Wizard';
|
|
|
33
33
|
export { WizardWithSidebar } from './WizardWithSidebar';
|
|
34
34
|
export { Drawer } from './Navigation/Drawer';
|
|
35
35
|
export { TextTruncate } from './text-truncate';
|
|
36
|
+
export { Toggle } from './Toggle';
|