@dtdot/lego 0.17.21 → 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.
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ import { ColourVariant } from '../../theme/theme.types';
3
+ export interface ActionMenuProps {
4
+ variant?: ColourVariant;
5
+ }
6
+ declare const ActionMenu: ({ variant }: ActionMenuProps) => JSX.Element;
7
+ export default ActionMenu;
@@ -0,0 +1,13 @@
1
+ import { faEllipsisV } from '@fortawesome/free-solid-svg-icons';
2
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
3
+ import React from 'react';
4
+ import styled from 'styled-components';
5
+ import Button from '../Button/Button.component';
6
+ const StyledIcon = styled(FontAwesomeIcon) `
7
+ font-size: 18px;
8
+ `;
9
+ const ActionMenu = ({ variant }) => {
10
+ return (React.createElement(Button, { variant: variant },
11
+ React.createElement(StyledIcon, { icon: faEllipsisV })));
12
+ };
13
+ export default ActionMenu;
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ import { Meta } from '@storybook/react/types-6-0';
3
+ export declare const Standard: () => JSX.Element;
4
+ export declare const Variants: () => JSX.Element;
5
+ declare const _default: Meta<import("@storybook/react/types-6-0").Args>;
6
+ export default _default;
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import { ActionMenu } from '../..';
3
+ /* eslint-disable @typescript-eslint/no-empty-function */
4
+ export const Standard = () => React.createElement(ActionMenu, null);
5
+ export const Variants = () => (React.createElement(React.Fragment, null,
6
+ React.createElement(ActionMenu, { variant: 'primary' }),
7
+ React.createElement("br", null),
8
+ React.createElement("br", null),
9
+ React.createElement(ActionMenu, { variant: 'secondary' }),
10
+ React.createElement("br", null),
11
+ React.createElement("br", null),
12
+ React.createElement(ActionMenu, { variant: 'tertiary' })));
13
+ export default {
14
+ title: 'Components/ActionMenu',
15
+ component: ActionMenu,
16
+ };
@@ -4,6 +4,7 @@ import getThemeVariantColours from '../../theme/helpers/getThemeVariantColours';
4
4
  import { BadgeSpan } from '../Badge/Badge.component';
5
5
  const InteractiveBadge = styled(BadgeSpan) `
6
6
  cursor: pointer;
7
+ margin-bottom: 8px;
7
8
 
8
9
  ${(props) => props.inactive &&
9
10
  `
@@ -12,6 +13,9 @@ const InteractiveBadge = styled(BadgeSpan) `
12
13
  `}
13
14
  `;
14
15
  const BadgeSelectorOuter = styled.div `
16
+ display: flex;
17
+ flex-wrap: wrap;
18
+
15
19
  ${InteractiveBadge} {
16
20
  margin-right: 8px;
17
21
  }
@@ -1,5 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { Meta } from '@storybook/react/types-6-0';
3
3
  export declare const Standard: () => JSX.Element;
4
+ export declare const LotsOfBadges: () => JSX.Element;
4
5
  declare const _default: Meta<import("@storybook/react/types-6-0").Args>;
5
6
  export default _default;
@@ -27,6 +27,67 @@ export const Standard = () => {
27
27
  const [value, setValue] = useState(['pending']);
28
28
  return React.createElement(BadgeSelector, { options: options, value: value, onChange: setValue });
29
29
  };
30
+ const options2 = [
31
+ {
32
+ value: 'one',
33
+ name: 'one',
34
+ variant: 'info',
35
+ },
36
+ {
37
+ value: 'two',
38
+ name: 'two',
39
+ variant: 'info',
40
+ },
41
+ {
42
+ value: 'three',
43
+ name: 'three',
44
+ variant: 'info',
45
+ },
46
+ {
47
+ value: 'four',
48
+ name: 'four',
49
+ variant: 'info',
50
+ },
51
+ {
52
+ value: 'five',
53
+ name: 'five',
54
+ variant: 'info',
55
+ },
56
+ {
57
+ value: 'six',
58
+ name: 'six',
59
+ variant: 'info',
60
+ },
61
+ {
62
+ value: 'seven',
63
+ name: 'seven',
64
+ variant: 'info',
65
+ },
66
+ {
67
+ value: 'eight',
68
+ name: 'eight',
69
+ variant: 'info',
70
+ },
71
+ {
72
+ value: 'nine',
73
+ name: 'nine',
74
+ variant: 'info',
75
+ },
76
+ {
77
+ value: 'ten',
78
+ name: 'ten',
79
+ variant: 'info',
80
+ },
81
+ {
82
+ value: 'eleven',
83
+ name: 'eleven',
84
+ variant: 'info',
85
+ },
86
+ ];
87
+ export const LotsOfBadges = () => {
88
+ const [value, setValue] = useState(['one']);
89
+ return React.createElement(BadgeSelector, { options: options2, value: value, onChange: setValue });
90
+ };
30
91
  export default {
31
92
  title: 'Components/BadgeSelector',
32
93
  component: BadgeSelector,
@@ -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,5 @@
1
+ /// <reference types="react" />
2
+ import { Meta } from '@storybook/react/types-6-0';
3
+ export declare const Standard: () => JSX.Element;
4
+ declare const _default: Meta<import("@storybook/react/types-6-0").Args>;
5
+ export default _default;
@@ -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;
@@ -6,6 +6,7 @@ export interface IInputProps {
6
6
  label?: string;
7
7
  placeholder?: string;
8
8
  type?: string;
9
+ autoFocus?: boolean;
9
10
  value?: string;
10
11
  error?: string;
11
12
  onChange?: (value: any) => void;
@@ -93,7 +93,7 @@ const messageVariants = {
93
93
  errorFocus: { opacity: 1, y: -4 },
94
94
  };
95
95
  const Input = React.forwardRef(function ForwardRefInput(props, ref) {
96
- const { label, name, placeholder, type = 'text', value, error: propsError, onChange, onFocus, onBlur } = props;
96
+ const { label, name, placeholder, type = 'text', autoFocus, value, error: propsError, onChange, onFocus, onBlur, } = props;
97
97
  const [isFocused, setIsFocused] = useState(false);
98
98
  const { value: contextValue, error: contextError, onChange: contextOnChange } = useFormNode(name);
99
99
  const error = contextError || propsError;
@@ -120,7 +120,7 @@ const Input = React.forwardRef(function ForwardRefInput(props, ref) {
120
120
  return (React.createElement("div", null,
121
121
  label && React.createElement(InputLabel, { htmlFor: name }, label),
122
122
  React.createElement(InputContainer, { animate: error ? (isFocused ? 'errorFocus' : 'error') : undefined },
123
- React.createElement(StyledInput, { ref: ref, variants: inputVariants, transition: { type: 'spring', duration: 0.3 }, type: type, name: name, placeholder: placeholder, value: getValue(value, contextValue), onChange: handleChange, onFocus: handleFocus, onBlur: handleBlur }),
123
+ React.createElement(StyledInput, { ref: ref, variants: inputVariants, transition: { type: 'spring', duration: 0.3 }, type: type, name: name, placeholder: placeholder, value: getValue(value, contextValue), onChange: handleChange, onFocus: handleFocus, onBlur: handleBlur, autoFocus: autoFocus }),
124
124
  React.createElement(ErrorContainer, { animate: error ? 'show' : undefined, style: { opacity: 0 }, variants: errorVariants, transition: { type: 'spring', duration: 0.3 } },
125
125
  React.createElement(ErrorInner, null,
126
126
  React.createElement(FontAwesomeIcon, { icon: faExclamationCircle }))),
package/build/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { default as BodyStyle } from './global/BodyStyle.component';
2
+ export { default as ActionMenu } from './components/ActionMenu/ActionMenu.component';
2
3
  export { default as ActionMessage } from './components/ActionMessage/ActionMessage.component';
3
4
  export { default as Alert } from './components/Alert/Alert.component';
4
5
  export { default as Badge } from './components/Badge/Badge.component';
@@ -7,6 +8,7 @@ export { default as Button } from './components/Button/Button.component';
7
8
  export { default as ButtonGroup } from './components/ButtonGroup/ButtonGroup.component';
8
9
  export { default as Card } from './components/Card/Card.component';
9
10
  export { default as CardGroup } from './components/Card/CardGroup.component';
11
+ export { default as Checklist } from './components/Checklist/Checklist.component';
10
12
  export { default as ControlGroup } from './components/ControlGroup/ControlGroup.component';
11
13
  export { default as FancyCheckbox } from './components/FancyCheckbox/FancyCheckbox.component';
12
14
  export { default as Form } from './components/Form/Form.component';
package/build/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { default as BodyStyle } from './global/BodyStyle.component';
2
+ export { default as ActionMenu } from './components/ActionMenu/ActionMenu.component';
2
3
  export { default as ActionMessage } from './components/ActionMessage/ActionMessage.component';
3
4
  export { default as Alert } from './components/Alert/Alert.component';
4
5
  export { default as Badge } from './components/Badge/Badge.component';
@@ -7,6 +8,7 @@ export { default as Button } from './components/Button/Button.component';
7
8
  export { default as ButtonGroup } from './components/ButtonGroup/ButtonGroup.component';
8
9
  export { default as Card } from './components/Card/Card.component';
9
10
  export { default as CardGroup } from './components/Card/CardGroup.component';
11
+ export { default as Checklist } from './components/Checklist/Checklist.component';
10
12
  export { default as ControlGroup } from './components/ControlGroup/ControlGroup.component';
11
13
  export { default as FancyCheckbox } from './components/FancyCheckbox/FancyCheckbox.component';
12
14
  export { default as Form } from './components/Form/Form.component';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dtdot/lego",
3
- "version": "0.17.21",
3
+ "version": "0.18.0",
4
4
  "description": "Some reusable components for building my applications",
5
5
  "main": "build/index.js",
6
6
  "scripts": {