@integrigo/integrigo-ui 1.6.17-e → 1.6.17-f
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.d.ts +1 -0
- package/lib/index.esm.js +1 -1
- package/lib/index.js +1 -1
- package/lib/src/components/molecules/Checkbox/Checkbox.stories.d.ts +4 -4
- package/lib/src/components/molecules/Radio/Radio.stories.d.ts +4 -4
- package/lib/src/components/molecules/Switch/Switch.d.ts +12 -0
- package/lib/src/components/molecules/Switch/Switch.stories.d.ts +7 -0
- package/lib/src/components/molecules/Switch/index.d.ts +1 -0
- package/lib/src/components/molecules/index.d.ts +1 -0
- package/lib/src/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/components/molecules/Switch/Switch.stories.tsx +36 -0
- package/src/components/molecules/Switch/Switch.tsx +91 -0
- package/src/components/molecules/Switch/index.ts +1 -0
- package/src/components/molecules/index.ts +1 -0
- package/src/index.ts +1 -0
@@ -1,19 +1,19 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { ComponentStory, ComponentMeta } from '@storybook/react';
|
3
|
-
declare const _default: ComponentMeta<React.ForwardRefExoticComponent<Omit<React.InputHTMLAttributes<HTMLInputElement>, "
|
3
|
+
declare const _default: ComponentMeta<React.ForwardRefExoticComponent<Omit<React.InputHTMLAttributes<HTMLInputElement>, "type" | "size"> & {
|
4
4
|
size?: "s" | "m" | "l" | "xl" | undefined;
|
5
5
|
label?: string | undefined;
|
6
6
|
} & React.RefAttributes<HTMLInputElement>>>;
|
7
7
|
export default _default;
|
8
|
-
export declare const Basic: ComponentStory<React.ForwardRefExoticComponent<Omit<React.InputHTMLAttributes<HTMLInputElement>, "
|
8
|
+
export declare const Basic: ComponentStory<React.ForwardRefExoticComponent<Omit<React.InputHTMLAttributes<HTMLInputElement>, "type" | "size"> & {
|
9
9
|
size?: "s" | "m" | "l" | "xl" | undefined;
|
10
10
|
label?: string | undefined;
|
11
11
|
} & React.RefAttributes<HTMLInputElement>>>;
|
12
|
-
export declare const Controlled: ComponentStory<React.ForwardRefExoticComponent<Omit<React.InputHTMLAttributes<HTMLInputElement>, "
|
12
|
+
export declare const Controlled: ComponentStory<React.ForwardRefExoticComponent<Omit<React.InputHTMLAttributes<HTMLInputElement>, "type" | "size"> & {
|
13
13
|
size?: "s" | "m" | "l" | "xl" | undefined;
|
14
14
|
label?: string | undefined;
|
15
15
|
} & React.RefAttributes<HTMLInputElement>>>;
|
16
|
-
export declare const WithLabel: ComponentStory<React.ForwardRefExoticComponent<Omit<React.InputHTMLAttributes<HTMLInputElement>, "
|
16
|
+
export declare const WithLabel: ComponentStory<React.ForwardRefExoticComponent<Omit<React.InputHTMLAttributes<HTMLInputElement>, "type" | "size"> & {
|
17
17
|
size?: "s" | "m" | "l" | "xl" | undefined;
|
18
18
|
label?: string | undefined;
|
19
19
|
} & React.RefAttributes<HTMLInputElement>>>;
|
@@ -1,20 +1,20 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { ComponentMeta, ComponentStory } from '@storybook/react';
|
3
3
|
import { Size } from './Radio';
|
4
|
-
declare const _default: ComponentMeta<React.ForwardRefExoticComponent<Omit<React.InputHTMLAttributes<HTMLInputElement>, "
|
4
|
+
declare const _default: ComponentMeta<React.ForwardRefExoticComponent<Omit<React.InputHTMLAttributes<HTMLInputElement>, "type" | "size"> & {
|
5
5
|
size?: Size | undefined;
|
6
6
|
label?: string | undefined;
|
7
7
|
} & React.RefAttributes<HTMLInputElement>>>;
|
8
8
|
export default _default;
|
9
|
-
export declare const Basic: ComponentStory<React.ForwardRefExoticComponent<Omit<React.InputHTMLAttributes<HTMLInputElement>, "
|
9
|
+
export declare const Basic: ComponentStory<React.ForwardRefExoticComponent<Omit<React.InputHTMLAttributes<HTMLInputElement>, "type" | "size"> & {
|
10
10
|
size?: Size | undefined;
|
11
11
|
label?: string | undefined;
|
12
12
|
} & React.RefAttributes<HTMLInputElement>>>;
|
13
|
-
export declare const Controlled: ComponentStory<React.ForwardRefExoticComponent<Omit<React.InputHTMLAttributes<HTMLInputElement>, "
|
13
|
+
export declare const Controlled: ComponentStory<React.ForwardRefExoticComponent<Omit<React.InputHTMLAttributes<HTMLInputElement>, "type" | "size"> & {
|
14
14
|
size?: Size | undefined;
|
15
15
|
label?: string | undefined;
|
16
16
|
} & React.RefAttributes<HTMLInputElement>>>;
|
17
|
-
export declare const WithLabel: ComponentStory<React.ForwardRefExoticComponent<Omit<React.InputHTMLAttributes<HTMLInputElement>, "
|
17
|
+
export declare const WithLabel: ComponentStory<React.ForwardRefExoticComponent<Omit<React.InputHTMLAttributes<HTMLInputElement>, "type" | "size"> & {
|
18
18
|
size?: Size | undefined;
|
19
19
|
label?: string | undefined;
|
20
20
|
} & React.RefAttributes<HTMLInputElement>>>;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import React from "react";
|
2
|
+
interface SwitchOption {
|
3
|
+
id: string;
|
4
|
+
name: string;
|
5
|
+
disabled?: boolean;
|
6
|
+
}
|
7
|
+
export interface SwitchProps {
|
8
|
+
options: [SwitchOption, SwitchOption] | [SwitchOption, SwitchOption, SwitchOption];
|
9
|
+
active?: SwitchOption["id"];
|
10
|
+
}
|
11
|
+
export declare const Switch: React.FC<SwitchProps>;
|
12
|
+
export {};
|
@@ -0,0 +1,7 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
import { ComponentStory, ComponentMeta } from "@storybook/react";
|
3
|
+
declare const _default: ComponentMeta<import("react").FC<import("./Switch").SwitchProps>>;
|
4
|
+
export default _default;
|
5
|
+
export declare const TwoOptions: ComponentStory<import("react").FC<import("./Switch").SwitchProps>>;
|
6
|
+
export declare const ThreeOptions: ComponentStory<import("react").FC<import("./Switch").SwitchProps>>;
|
7
|
+
export declare const ThreeWithDisabled: ComponentStory<import("react").FC<import("./Switch").SwitchProps>>;
|
@@ -0,0 +1 @@
|
|
1
|
+
export { Switch } from './Switch';
|
package/lib/src/index.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
export { Alert, Avatar, Card, Divider, DateTime, Icon, Nav, Pill, Typography, Spinner, Chip, Dot, Gradient, } from "./components/atoms";
|
2
|
-
export { InfoCard, Input, TextArea, Button, Checkbox, Dropdown, Profile, Radio, Tile, } from "./components/molecules";
|
2
|
+
export { InfoCard, Input, TextArea, Button, Checkbox, Dropdown, Profile, Radio, Tile, Switch, } from "./components/molecules";
|
3
3
|
export { Menu, Setting, Modal, Select } from "./components/organisms";
|
4
4
|
export { GlobalStyles as IntegrigoUI, Color } from "./styles";
|
package/package.json
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
import { ComponentStory, ComponentMeta } from "@storybook/react";
|
2
|
+
|
3
|
+
import { Switch } from "./Switch";
|
4
|
+
|
5
|
+
export default {
|
6
|
+
title: "Molecules/Switch",
|
7
|
+
component: Switch,
|
8
|
+
} as ComponentMeta<typeof Switch>;
|
9
|
+
|
10
|
+
const Template: ComponentStory<typeof Switch> = (args) => <Switch {...args} />;
|
11
|
+
|
12
|
+
export const TwoOptions = Template.bind({});
|
13
|
+
TwoOptions.args = {
|
14
|
+
options: [
|
15
|
+
{ id: "1", name: "One" },
|
16
|
+
{ id: "2", name: "Two" },
|
17
|
+
],
|
18
|
+
};
|
19
|
+
|
20
|
+
export const ThreeOptions = Template.bind({});
|
21
|
+
ThreeOptions.args = {
|
22
|
+
options: [
|
23
|
+
{ id: "1", name: "One" },
|
24
|
+
{ id: "2", name: "Two" },
|
25
|
+
{ id: "3", name: "Three" },
|
26
|
+
],
|
27
|
+
};
|
28
|
+
|
29
|
+
export const ThreeWithDisabled = Template.bind({});
|
30
|
+
ThreeWithDisabled.args = {
|
31
|
+
options: [
|
32
|
+
{ id: "1", name: "One" },
|
33
|
+
{ id: "2", name: "Two", disabled: true },
|
34
|
+
{ id: "3", name: "Three" },
|
35
|
+
],
|
36
|
+
};
|
@@ -0,0 +1,91 @@
|
|
1
|
+
import React, { useState } from "react";
|
2
|
+
import styled from "styled-components";
|
3
|
+
|
4
|
+
interface SwitchOption {
|
5
|
+
id: string;
|
6
|
+
name: string;
|
7
|
+
disabled?: boolean;
|
8
|
+
}
|
9
|
+
|
10
|
+
export interface SwitchProps {
|
11
|
+
options:
|
12
|
+
| [SwitchOption, SwitchOption]
|
13
|
+
| [SwitchOption, SwitchOption, SwitchOption];
|
14
|
+
active?: SwitchOption["id"];
|
15
|
+
}
|
16
|
+
|
17
|
+
export const Switch: React.FC<SwitchProps> = ({
|
18
|
+
options,
|
19
|
+
active: defaultActive,
|
20
|
+
}) => {
|
21
|
+
const [active, setActive] = useState(defaultActive);
|
22
|
+
|
23
|
+
const activeOption = options.find(({ id }) => id === active);
|
24
|
+
const offset = activeOption ? options.indexOf(activeOption) : 0;
|
25
|
+
|
26
|
+
const handleOptionClick = (id: string, disabled?: boolean) => {
|
27
|
+
if (disabled) {
|
28
|
+
return;
|
29
|
+
}
|
30
|
+
|
31
|
+
setActive(id);
|
32
|
+
};
|
33
|
+
|
34
|
+
return (
|
35
|
+
<Root count={options.length} offset={offset}>
|
36
|
+
{options.map((option) => (
|
37
|
+
<Option
|
38
|
+
onClick={() => handleOptionClick(option.id, option.disabled)}
|
39
|
+
key={option.id}
|
40
|
+
disabled={option.disabled}
|
41
|
+
>
|
42
|
+
{option.name}
|
43
|
+
</Option>
|
44
|
+
))}
|
45
|
+
</Root>
|
46
|
+
);
|
47
|
+
};
|
48
|
+
|
49
|
+
const Root = styled.div<{ count: number; offset: number }>`
|
50
|
+
border-radius: var(--padding-l);
|
51
|
+
background-color: var(--shades-of-grey-20);
|
52
|
+
gap: 0;
|
53
|
+
position: relative;
|
54
|
+
display: flex;
|
55
|
+
padding: var(--padding-s) 0;
|
56
|
+
|
57
|
+
& > div {
|
58
|
+
transition: color var(--transition-speed);
|
59
|
+
}
|
60
|
+
|
61
|
+
& > div:nth-child(${(p) => p.offset + 1}) {
|
62
|
+
color: white;
|
63
|
+
}
|
64
|
+
|
65
|
+
&::after {
|
66
|
+
content: "";
|
67
|
+
position: absolute;
|
68
|
+
background-color: var(--color-orange);
|
69
|
+
box-shadow: 1px 1px 10px rgba(0, 0, 0, 0.2);
|
70
|
+
width: ${(p) => `calc(100% / ${p.count})`};
|
71
|
+
height: 100%;
|
72
|
+
transform: ${(p) => `translateX(calc(${p.offset} * 100%))`};
|
73
|
+
left: 0;
|
74
|
+
top: 0;
|
75
|
+
border-radius: var(--padding-xl);
|
76
|
+
z-index: 1;
|
77
|
+
transition: transform var(--transition-speed);
|
78
|
+
}
|
79
|
+
`;
|
80
|
+
|
81
|
+
const Option = styled.div<{ disabled?: boolean }>`
|
82
|
+
flex: 1;
|
83
|
+
font-weight: var(--font-medium);
|
84
|
+
display: flex;
|
85
|
+
${(p) => p.disabled && "color: var(--shades-of-grey-40)"};
|
86
|
+
cursor: ${(p) => (p.disabled ? "default" : "pointer")};
|
87
|
+
justify-content: center;
|
88
|
+
align-items: center;
|
89
|
+
position: relative;
|
90
|
+
z-index: ${(p) => (p.disabled ? 0 : 2)};
|
91
|
+
`;
|
@@ -0,0 +1 @@
|
|
1
|
+
export { Switch } from './Switch'
|