@dtdot/lego 0.17.23 → 0.18.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/build/components/Checklist/Checklist.component.d.ts +12 -0
- package/build/components/Checklist/Checklist.component.js +45 -0
- package/build/components/Checklist/Checklist.stories.d.ts +5 -0
- package/build/components/Checklist/Checklist.stories.js +42 -0
- package/build/components/Checklist/_ChecklistItem.component.d.ts +8 -0
- package/build/components/Checklist/_ChecklistItem.component.js +78 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export interface ChecklistItemProps {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
}
|
|
6
|
+
export interface ChecklistProps {
|
|
7
|
+
items: ChecklistItemProps[];
|
|
8
|
+
value: string[];
|
|
9
|
+
onChange: (value: string[]) => void;
|
|
10
|
+
}
|
|
11
|
+
declare const Checklist: ({ items, value, onChange }: ChecklistProps) => JSX.Element;
|
|
12
|
+
export default Checklist;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
import { motion, LayoutGroup } from 'framer-motion';
|
|
4
|
+
import ChecklistItem from './_ChecklistItem.component';
|
|
5
|
+
const ListDivider = styled.div `
|
|
6
|
+
width: 100%;
|
|
7
|
+
height: 0px;
|
|
8
|
+
|
|
9
|
+
padding: 20px 0;
|
|
10
|
+
`;
|
|
11
|
+
const Checklist = ({ items, value, onChange }) => {
|
|
12
|
+
const [checkedOrder, setCheckedOrder] = useState([]);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (value.some((id) => !checkedOrder.includes(id))) {
|
|
15
|
+
const newCheckedOrder = [...checkedOrder];
|
|
16
|
+
value.forEach((valueId) => {
|
|
17
|
+
if (!newCheckedOrder.includes(valueId)) {
|
|
18
|
+
newCheckedOrder.push(valueId);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
setCheckedOrder(newCheckedOrder);
|
|
22
|
+
}
|
|
23
|
+
}, [value, checkedOrder, setCheckedOrder]);
|
|
24
|
+
const handleChange = (id, checked) => {
|
|
25
|
+
if (checked && !value.includes(id)) {
|
|
26
|
+
onChange([...value, id]);
|
|
27
|
+
setCheckedOrder([id, ...checkedOrder]);
|
|
28
|
+
}
|
|
29
|
+
else if (!checked && value.includes(id)) {
|
|
30
|
+
onChange(value.filter((_id) => _id !== id));
|
|
31
|
+
setCheckedOrder(checkedOrder.filter((_id) => _id !== id));
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const checkedItems = items
|
|
35
|
+
.filter((item) => value.includes(item.id))
|
|
36
|
+
.sort((a, b) => checkedOrder.indexOf(a.id) - checkedOrder.indexOf(b.id));
|
|
37
|
+
const unCheckedItems = items.filter((item) => !value.includes(item.id));
|
|
38
|
+
return (React.createElement(LayoutGroup, null,
|
|
39
|
+
unCheckedItems.map((item) => (React.createElement(motion.div, { layoutId: item.id, key: item.id, transition: { duration: 0.2 } },
|
|
40
|
+
React.createElement(ChecklistItem, { label: item.label, value: value.includes(item.id), onChange: (checked) => handleChange(item.id, checked) })))),
|
|
41
|
+
checkedItems.length ? React.createElement(ListDivider, null) : null,
|
|
42
|
+
checkedItems.map((item) => (React.createElement(motion.div, { layoutId: item.id, key: item.id, transition: { duration: 0.2 } },
|
|
43
|
+
React.createElement(ChecklistItem, { label: item.label, value: value.includes(item.id), onChange: (checked) => handleChange(item.id, checked) }))))));
|
|
44
|
+
};
|
|
45
|
+
export default Checklist;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { Checklist } from '../..';
|
|
3
|
+
const items = [
|
|
4
|
+
{
|
|
5
|
+
id: '1',
|
|
6
|
+
value: 'one',
|
|
7
|
+
label: 'one',
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
id: '2',
|
|
11
|
+
value: 'two',
|
|
12
|
+
label: 'two',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
id: '3',
|
|
16
|
+
value: 'three',
|
|
17
|
+
label: 'three',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
id: '4',
|
|
21
|
+
value: 'four',
|
|
22
|
+
label: 'four',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
id: '5',
|
|
26
|
+
value: 'five',
|
|
27
|
+
label: 'five',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
id: '6',
|
|
31
|
+
value: 'six',
|
|
32
|
+
label: 'six',
|
|
33
|
+
},
|
|
34
|
+
];
|
|
35
|
+
export const Standard = () => {
|
|
36
|
+
const [value, setValue] = useState(['2', '4']);
|
|
37
|
+
return React.createElement(Checklist, { items: items, value: value, onChange: setValue });
|
|
38
|
+
};
|
|
39
|
+
export default {
|
|
40
|
+
title: 'Components/Checklist',
|
|
41
|
+
component: Checklist,
|
|
42
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export interface ChecklistItemProps {
|
|
3
|
+
label: string;
|
|
4
|
+
value: boolean;
|
|
5
|
+
onChange: (value: boolean) => void;
|
|
6
|
+
}
|
|
7
|
+
declare const ChecklistItem: ({ label, value, onChange }: ChecklistItemProps) => JSX.Element;
|
|
8
|
+
export default ChecklistItem;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { motion } from 'framer-motion';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import styled, { useTheme } from 'styled-components';
|
|
4
|
+
const Outerlabel = styled(motion.label) `
|
|
5
|
+
position: relative;
|
|
6
|
+
margin-bottom: 4px;
|
|
7
|
+
padding: 4px;
|
|
8
|
+
|
|
9
|
+
display: flex;
|
|
10
|
+
align-items: center;
|
|
11
|
+
|
|
12
|
+
font-size: ${(props) => props.theme.fonts.default.size};
|
|
13
|
+
font-family: ${(props) => props.theme.fonts.default.family};
|
|
14
|
+
font-weight: ${(props) => props.theme.fonts.default.weight};
|
|
15
|
+
color: ${(props) => (props.checked ? props.theme.colours.defaultBorder : props.theme.colours.defaultFont)};
|
|
16
|
+
|
|
17
|
+
background-color: ${(props) => props.theme.colours.background};
|
|
18
|
+
|
|
19
|
+
user-select: none;
|
|
20
|
+
cursor: pointer;
|
|
21
|
+
`;
|
|
22
|
+
const HiddenCheckbox = styled.input `
|
|
23
|
+
position: absolute;
|
|
24
|
+
opacity: 0;
|
|
25
|
+
cursor: pointer;
|
|
26
|
+
height: 0;
|
|
27
|
+
width: 0;
|
|
28
|
+
`;
|
|
29
|
+
const Checkmark = styled.div `
|
|
30
|
+
position: relative;
|
|
31
|
+
height: 24px;
|
|
32
|
+
width: 24px;
|
|
33
|
+
margin-right: 8px;
|
|
34
|
+
background-color: ${(props) => props.theme.colours.cardBackground};
|
|
35
|
+
|
|
36
|
+
&:after {
|
|
37
|
+
content: '';
|
|
38
|
+
position: absolute;
|
|
39
|
+
display: ${(props) => (props.checked ? 'block' : 'none')};
|
|
40
|
+
|
|
41
|
+
left: 9px;
|
|
42
|
+
top: 5px;
|
|
43
|
+
width: 5px;
|
|
44
|
+
height: 10px;
|
|
45
|
+
border: solid ${(props) => props.theme.colours.defaultFont};
|
|
46
|
+
border-width: 0 3px 3px 0;
|
|
47
|
+
-webkit-transform: rotate(45deg);
|
|
48
|
+
-ms-transform: rotate(45deg);
|
|
49
|
+
transform: rotate(45deg);
|
|
50
|
+
}
|
|
51
|
+
`;
|
|
52
|
+
const Strikethrough = styled.div `
|
|
53
|
+
position: absolute;
|
|
54
|
+
color: transparent;
|
|
55
|
+
height: 1px;
|
|
56
|
+
|
|
57
|
+
margin-left: 30px;
|
|
58
|
+
padding-right: 2px;
|
|
59
|
+
padding-left: 2px;
|
|
60
|
+
background-color: ${(props) => props.theme.colours.defaultBorder};
|
|
61
|
+
`;
|
|
62
|
+
const ChecklistItem = ({ label, value, onChange }) => {
|
|
63
|
+
const theme = useTheme();
|
|
64
|
+
const handleChange = (event) => {
|
|
65
|
+
if (event.target.checked) {
|
|
66
|
+
onChange(true);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
onChange(false);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
return (React.createElement(Outerlabel, { checked: value, whileHover: { backgroundColor: theme.colours.cardBackground } },
|
|
73
|
+
React.createElement(Checkmark, { checked: value }),
|
|
74
|
+
label,
|
|
75
|
+
React.createElement(HiddenCheckbox, { type: 'checkbox', checked: value, onChange: handleChange }),
|
|
76
|
+
value && React.createElement(Strikethrough, null, label)));
|
|
77
|
+
};
|
|
78
|
+
export default ChecklistItem;
|
package/build/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export { default as Button } from './components/Button/Button.component';
|
|
|
8
8
|
export { default as ButtonGroup } from './components/ButtonGroup/ButtonGroup.component';
|
|
9
9
|
export { default as Card } from './components/Card/Card.component';
|
|
10
10
|
export { default as CardGroup } from './components/Card/CardGroup.component';
|
|
11
|
+
export { default as Checklist } from './components/Checklist/Checklist.component';
|
|
11
12
|
export { default as ControlGroup } from './components/ControlGroup/ControlGroup.component';
|
|
12
13
|
export { default as FancyCheckbox } from './components/FancyCheckbox/FancyCheckbox.component';
|
|
13
14
|
export { default as Form } from './components/Form/Form.component';
|
package/build/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export { default as Button } from './components/Button/Button.component';
|
|
|
8
8
|
export { default as ButtonGroup } from './components/ButtonGroup/ButtonGroup.component';
|
|
9
9
|
export { default as Card } from './components/Card/Card.component';
|
|
10
10
|
export { default as CardGroup } from './components/Card/CardGroup.component';
|
|
11
|
+
export { default as Checklist } from './components/Checklist/Checklist.component';
|
|
11
12
|
export { default as ControlGroup } from './components/ControlGroup/ControlGroup.component';
|
|
12
13
|
export { default as FancyCheckbox } from './components/FancyCheckbox/FancyCheckbox.component';
|
|
13
14
|
export { default as Form } from './components/Form/Form.component';
|