imbric-theme 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- package/.babelrc.json +3 -0
- package/.commitlintrc.json +3 -0
- package/.editorconfig +13 -0
- package/.eslintcache +1 -0
- package/.eslintrc.json +36 -0
- package/.huskyrc.json +6 -0
- package/.lintstagedrc.json +5 -0
- package/.nvmrc +1 -0
- package/.prettierrc.json +4 -0
- package/.releaserc.json +13 -0
- package/.storybook/main.js +9 -0
- package/.storybook/preview-head.html +2 -0
- package/.storybook/preview.js +32 -0
- package/.stylelintrc.json +14 -0
- package/.vscode/launch.json +15 -0
- package/CHANGELOG.md +0 -0
- package/README.md +69 -0
- package/atoms/Avatar/Avatar.js +36 -0
- package/atoms/Avatar/Avatar.module.css +3 -0
- package/atoms/Avatar/Avatar.stories.js +29 -0
- package/atoms/Avatar/__snapshots__/Avatar.stories.js.snap +105 -0
- package/atoms/Avatar/constants.js +3 -0
- package/atoms/Avatar/helpers.js +7 -0
- package/atoms/Avatar/index.js +3 -0
- package/atoms/Button/Button.js +68 -0
- package/atoms/Button/Button.module.css +63 -0
- package/atoms/Button/Button.stories.js +47 -0
- package/atoms/Button/Button.test.js +60 -0
- package/atoms/Button/__snapshots__/Button.stories.js.snap +191 -0
- package/atoms/Button/constants.js +3 -0
- package/atoms/Button/index.js +3 -0
- package/atoms/Card/Card.js +48 -0
- package/atoms/Card/Card.module.css +52 -0
- package/atoms/Card/Card.stories.js +41 -0
- package/atoms/Card/__snapshots__/Card.stories.js.snap +136 -0
- package/atoms/Card/constants.js +4 -0
- package/atoms/Card/index.js +3 -0
- package/atoms/Check/Check.js +26 -0
- package/atoms/Check/Check.module.css +11 -0
- package/atoms/Check/Check.stories.js +15 -0
- package/atoms/Check/__snapshots__/Check.stories.js.snap +67 -0
- package/atoms/Check/index.js +2 -0
- package/atoms/Divider/Divider.js +19 -0
- package/atoms/Divider/Divider.module.css +5 -0
- package/atoms/Divider/Divider.stories.js +12 -0
- package/atoms/Divider/__snapshots__/Divider.stories.js.snap +22 -0
- package/atoms/Divider/index.js +2 -0
- package/atoms/Heading/Heading.js +37 -0
- package/atoms/Heading/Heading.module.css +66 -0
- package/atoms/Heading/Heading.stories.js +46 -0
- package/atoms/Heading/__snapshots__/Heading.stories.js.snap +189 -0
- package/atoms/Heading/constants.js +5 -0
- package/atoms/Heading/index.js +3 -0
- package/atoms/Icon/Icon.js +66 -0
- package/atoms/Icon/Icon.module.css +112 -0
- package/atoms/Icon/Icon.stories.js +48 -0
- package/atoms/Icon/__snapshots__/Icon.stories.js.snap +1311 -0
- package/atoms/Icon/constants.js +486 -0
- package/atoms/Icon/helpers.js +9 -0
- package/atoms/Icon/index.js +3 -0
- package/atoms/Input/Input.js +49 -0
- package/atoms/Input/Input.module.css +27 -0
- package/atoms/Input/Input.stories.js +32 -0
- package/atoms/Input/__snapshots__/Input.stories.js.snap +101 -0
- package/atoms/Input/constants.js +3 -0
- package/atoms/Input/index.js +3 -0
- package/atoms/Link/Link.js +33 -0
- package/atoms/Link/Link.module.css +14 -0
- package/atoms/Link/Link.stories.js +30 -0
- package/atoms/Link/__snapshots__/Link.stories.js.snap +118 -0
- package/atoms/Link/constants.js +5 -0
- package/atoms/Link/index.js +3 -0
- package/atoms/Loading/Loading.js +30 -0
- package/atoms/Loading/Loading.module.css +51 -0
- package/atoms/Loading/Loading.stories.js +17 -0
- package/atoms/Loading/__snapshots__/Loading.stories.js.snap +26 -0
- package/atoms/Loading/index.js +2 -0
- package/atoms/Modal/Modal.js +98 -0
- package/atoms/Modal/Modal.module.css +85 -0
- package/atoms/Modal/Modal.stories.js +43 -0
- package/atoms/Modal/__snapshots__/Modal.stories.js.snap +239 -0
- package/atoms/Modal/constants.js +1 -0
- package/atoms/Modal/index.js +3 -0
- package/atoms/Paragraph/Paragraph.js +56 -0
- package/atoms/Paragraph/Paragraph.module.css +68 -0
- package/atoms/Paragraph/Paragraph.stories.js +52 -0
- package/atoms/Paragraph/__snapshots__/Paragraph.stories.js.snap +230 -0
- package/atoms/Paragraph/constants.js +5 -0
- package/atoms/Paragraph/index.js +3 -0
- package/atoms/Picture/Picture.js +40 -0
- package/atoms/Picture/Picture.module.css +16 -0
- package/atoms/Picture/Picture.stories.js +32 -0
- package/atoms/Picture/__snapshots__/Picture.stories.js.snap +156 -0
- package/atoms/Picture/index.js +2 -0
- package/atoms/Textarea/Textarea.js +46 -0
- package/atoms/Textarea/Textarea.module.css +25 -0
- package/atoms/Textarea/Textarea.stories.js +16 -0
- package/atoms/Textarea/__snapshots__/Textarea.stories.js.snap +25 -0
- package/atoms/Textarea/index.js +2 -0
- package/codecov.yml +2 -0
- package/helpers/storybook.js +29 -0
- package/helpers/storybook.test.js +40 -0
- package/helpers/styles.js +37 -0
- package/helpers/styles.test.js +222 -0
- package/hocs/withStyles.js +17 -0
- package/hook/useMedia.js +22 -0
- package/index.js +31 -0
- package/jest.config.js +23 -0
- package/jest.setup.js +13 -0
- package/layout/CenteredContent/CenteredContent.js +30 -0
- package/layout/CenteredContent/CenteredContent.module.css +12 -0
- package/layout/CenteredContent/CenteredContent.stories.js +22 -0
- package/layout/CenteredContent/__snapshots__/CenteredContent.stories.js.snap +27 -0
- package/layout/CenteredContent/index.js +2 -0
- package/layout/Container/Container.js +29 -0
- package/layout/Container/Container.module.css +14 -0
- package/layout/Container/Container.stories.js +22 -0
- package/layout/Container/__snapshots__/Container.stories.js.snap +27 -0
- package/layout/Container/index.js +2 -0
- package/layout/FullHeightContent/FullHeightContent.js +40 -0
- package/layout/FullHeightContent/FullHeightContent.module.css +21 -0
- package/layout/FullHeightContent/FullHeightContent.stories.js +22 -0
- package/layout/FullHeightContent/__snapshots__/FullHeightContent.stories.js.snap +41 -0
- package/layout/FullHeightContent/index.js +2 -0
- package/layout/Spacer/Spacer.js +40 -0
- package/layout/Spacer/Spacer.module.css +12 -0
- package/layout/Spacer/Spacer.stories.js +25 -0
- package/layout/Spacer/__snapshots__/Spacer.stories.js.snap +97 -0
- package/layout/Spacer/components/Horizontal/Horizontal.js +43 -0
- package/layout/Spacer/components/Horizontal/Horizontal.stories.js +32 -0
- package/layout/Spacer/components/Horizontal/__snapshots__/Horizontal.stories.js.snap +97 -0
- package/layout/Spacer/components/Horizontal/index.js +1 -0
- package/layout/Spacer/components/Vertical/Vertical.js +31 -0
- package/layout/Spacer/components/Vertical/Vertical.stories.js +25 -0
- package/layout/Spacer/components/Vertical/__snapshots__/Vertical.stories.js.snap +85 -0
- package/layout/Spacer/components/Vertical/index.js +1 -0
- package/layout/Spacer/components/index.js +2 -0
- package/layout/Spacer/constants.js +5 -0
- package/layout/Spacer/helpers.js +3 -0
- package/layout/Spacer/index.js +3 -0
- package/molecules/Accordion/Accordion.js +70 -0
- package/molecules/Accordion/Accordion.module.css +12 -0
- package/molecules/Accordion/Accordion.stories.js +31 -0
- package/molecules/Accordion/__snapshots__/Accordion.stories.js.snap +228 -0
- package/molecules/Accordion/index.js +2 -0
- package/molecules/AddButton/AddButton.js +137 -0
- package/molecules/AddButton/AddButton.module.css +128 -0
- package/molecules/AddButton/AddButton.stories.js +47 -0
- package/molecules/AddButton/__snapshots__/AddButton.stories.js.snap +326 -0
- package/molecules/AddButton/constants.js +6 -0
- package/molecules/AddButton/handlers.js +58 -0
- package/molecules/AddButton/handlers.test.js +19 -0
- package/molecules/AddButton/helpers.js +6 -0
- package/molecules/AddButton/helpers.test.js +41 -0
- package/molecules/AddButton/hooks.js +14 -0
- package/molecules/AddButton/index.js +3 -0
- package/molecules/ButtonIcon/ButtonIcon.js +41 -0
- package/molecules/ButtonIcon/ButtonIcon.stories.js +27 -0
- package/molecules/ButtonIcon/__snapshots__/ButtonIcon.stories.js.snap +178 -0
- package/molecules/ButtonIcon/constants.js +6 -0
- package/molecules/ButtonIcon/index.js +2 -0
- package/molecules/Dropdown/Dropdown.js +59 -0
- package/molecules/Dropdown/Dropdown.module.css +34 -0
- package/molecules/Dropdown/Dropdown.stories.js +41 -0
- package/molecules/Dropdown/__snapshots__/Dropdown.stories.js.snap +181 -0
- package/molecules/Dropdown/index.js +2 -0
- package/molecules/Error/Error.js +35 -0
- package/molecules/Error/Error.module.css +11 -0
- package/molecules/Error/Error.stories.js +18 -0
- package/molecules/Error/__snapshots__/Error.stories.js.snap +134 -0
- package/molecules/Error/index.js +2 -0
- package/molecules/IconLabel/IconLabel.js +83 -0
- package/molecules/IconLabel/IconLabel.module.css +16 -0
- package/molecules/IconLabel/IconLabel.stories.js +25 -0
- package/molecules/IconLabel/__snapshots__/IconLabel.stories.js.snap +211 -0
- package/molecules/IconLabel/constants.js +6 -0
- package/molecules/IconLabel/index.js +3 -0
- package/molecules/LoadingError/LoadingError.js +31 -0
- package/molecules/LoadingError/LoadingError.stories.js +24 -0
- package/molecules/LoadingError/__snapshots__/LoadingError.stories.js.snap +109 -0
- package/molecules/LoadingError/index.js +1 -0
- package/molecules/Score/Score.js +61 -0
- package/molecules/Score/Score.module.css +11 -0
- package/molecules/Score/Score.stories.js +13 -0
- package/molecules/Score/__snapshots__/Score.stories.js.snap +100 -0
- package/molecules/Score/faces/happy.svg +7 -0
- package/molecules/Score/faces/normal.svg +6 -0
- package/molecules/Score/faces/sad.svg +6 -0
- package/molecules/Score/index.js +2 -0
- package/molecules/Task/Task.js +114 -0
- package/molecules/Task/Task.module.css +47 -0
- package/molecules/Task/Task.stories.js +47 -0
- package/molecules/Task/__snapshots__/Task.stories.js.snap +953 -0
- package/molecules/Task/constants.js +1 -0
- package/molecules/Task/index.js +3 -0
- package/molecules/TaskCounter/TaskCounter.js +74 -0
- package/molecules/TaskCounter/TaskCounter.module.css +11 -0
- package/molecules/TaskCounter/TaskCounter.stories.js +26 -0
- package/molecules/TaskCounter/__snapshots__/TaskCounter.stories.js.snap +177 -0
- package/molecules/TaskCounter/index.js +2 -0
- package/package.json +102 -0
- package/scripts/build-tokens.js +40 -0
- package/scripts/create-component.js +127 -0
- package/storybook.test.js +13 -0
- package/styles/globals.css +10 -0
- package/styles/tokens.css +390 -0
- package/templates/component/Component.js +22 -0
- package/templates/component/Component.module.css +3 -0
- package/templates/component/Component.stories.js +23 -0
- package/templates/component/constants.js +1 -0
- package/templates/component/index.js +3 -0
- package/tokens/Token/Helper.js +30 -0
- package/tokens/Token/Token.js +13 -0
- package/tokens/Token/Token.module.css +64 -0
- package/tokens/Token/components/Color.js +21 -0
- package/tokens/Token/components/Color.stories.js +126 -0
- package/tokens/Token/components/FontFamily.js +24 -0
- package/tokens/Token/components/FontFamily.stories.js +32 -0
- package/tokens/Token/components/FontSize.js +24 -0
- package/tokens/Token/components/FontSize.stories.js +31 -0
- package/tokens/Token/components/FontWeight.js +24 -0
- package/tokens/Token/components/FontWeight.stories.js +31 -0
- package/tokens/Token/components/Spacing.js +24 -0
- package/tokens/Token/components/Spacing.stories.js +29 -0
- package/tokens/Token/components/__snapshots__/Color.stories.js.snap +7169 -0
- package/tokens/Token/components/__snapshots__/FontFamily.stories.js.snap +133 -0
- package/tokens/Token/components/__snapshots__/FontSize.stories.js.snap +261 -0
- package/tokens/Token/components/__snapshots__/FontWeight.stories.js.snap +317 -0
- package/tokens/Token/components/__snapshots__/Spacing.stories.js.snap +229 -0
- package/tokens/Token/components/index.js +5 -0
- package/tokens/Token/helpers.js +17 -0
- package/tokens/Token/index.js +1 -0
- package/tokens/index.js +471 -0
- package/utils/isEmpty.js +28 -0
- package/utils/isEmpty.test.js +125 -0
- package/utils/isObject.js +4 -0
- package/utils/keyboardCodes.js +6 -0
- package/utils/testUtils/matchMediaMock.js +14 -0
- package/utils/testUtils/svgrMock.js +2 -0
- package/utils/toCapitalize.js +4 -0
- package/utils/toKebabCase.js +8 -0
- package/utils/toPascalCase.js +20 -0
- package/webpack/cssModules.js +30 -0
- package/webpack/loadConfigs.js +6 -0
- package/webpack/reactInlineSvg.js +22 -0
@@ -0,0 +1,137 @@
|
|
1
|
+
import React, { useState, useRef } from 'react'
|
2
|
+
import PropTypes from 'prop-types'
|
3
|
+
|
4
|
+
import Paragraph from '../../atoms/Paragraph'
|
5
|
+
import Icon from '../../atoms/Icon'
|
6
|
+
import Spacer from '../../layout/Spacer'
|
7
|
+
|
8
|
+
import styles from './AddButton.module.css'
|
9
|
+
import { options } from './constants'
|
10
|
+
import {
|
11
|
+
handleClick,
|
12
|
+
handleChange,
|
13
|
+
handleKeyDown,
|
14
|
+
handleBlur,
|
15
|
+
handleFocus,
|
16
|
+
} from './handlers'
|
17
|
+
import { useKeydownEnterKey } from './hooks'
|
18
|
+
import { shouldShowHelpText } from './helpers'
|
19
|
+
import withStyles from '../../hocs/withStyles'
|
20
|
+
|
21
|
+
export const AddButton = ({
|
22
|
+
id,
|
23
|
+
getStyles,
|
24
|
+
children,
|
25
|
+
focusHelpText,
|
26
|
+
blurHelpText,
|
27
|
+
type,
|
28
|
+
icon,
|
29
|
+
onAdd,
|
30
|
+
defaultIsEditable,
|
31
|
+
defaultIsFocused,
|
32
|
+
defaultValue,
|
33
|
+
defaultIsInvalid,
|
34
|
+
}) => {
|
35
|
+
const [isEditable, setIsEditable] = useState(defaultIsEditable)
|
36
|
+
const [inputValue, setInputValue] = useState(defaultValue)
|
37
|
+
const [isInvalid, setIsInvalid] = useState(defaultIsInvalid)
|
38
|
+
const [isFocused, setIsFocused] = useState(defaultIsFocused)
|
39
|
+
const inputRef = useRef(null)
|
40
|
+
|
41
|
+
useKeydownEnterKey(() => setIsEditable(true))
|
42
|
+
|
43
|
+
return (
|
44
|
+
<div
|
45
|
+
id={`${id}-add-button`}
|
46
|
+
className={getStyles('add-button', ['type'], {
|
47
|
+
'is-editable': isEditable,
|
48
|
+
'is-focused': isFocused,
|
49
|
+
'is-invalid': isInvalid,
|
50
|
+
})}
|
51
|
+
onClick={handleClick({ setIsEditable, inputRef })}
|
52
|
+
>
|
53
|
+
{isEditable ? (
|
54
|
+
<div className={getStyles('edit-container')}>
|
55
|
+
<input
|
56
|
+
id={`${id}-add-button-input`}
|
57
|
+
ref={inputRef}
|
58
|
+
type="text"
|
59
|
+
value={inputValue}
|
60
|
+
autoFocus={!defaultIsEditable}
|
61
|
+
onFocus={handleFocus({ setIsFocused })}
|
62
|
+
onBlur={handleBlur({
|
63
|
+
inputValue,
|
64
|
+
setIsEditable,
|
65
|
+
setIsFocused,
|
66
|
+
setIsInvalid,
|
67
|
+
})}
|
68
|
+
onChange={handleChange({ setInputValue, setIsInvalid })}
|
69
|
+
onKeyDown={handleKeyDown({
|
70
|
+
setInputValue,
|
71
|
+
setIsEditable,
|
72
|
+
inputValue,
|
73
|
+
setIsInvalid,
|
74
|
+
onAdd,
|
75
|
+
})}
|
76
|
+
/>
|
77
|
+
{shouldShowHelpText({
|
78
|
+
isEditable,
|
79
|
+
inputValue,
|
80
|
+
focusHelpText,
|
81
|
+
blurHelpText,
|
82
|
+
}) && (
|
83
|
+
<>
|
84
|
+
<Paragraph
|
85
|
+
size="sm"
|
86
|
+
className="help-text"
|
87
|
+
color={isFocused ? 'muted' : 'inverted'}
|
88
|
+
>
|
89
|
+
{isFocused ? focusHelpText : blurHelpText}
|
90
|
+
</Paragraph>
|
91
|
+
<Spacer.Horizontal size="sm" />
|
92
|
+
</>
|
93
|
+
)}
|
94
|
+
</div>
|
95
|
+
) : (
|
96
|
+
<>
|
97
|
+
<Icon
|
98
|
+
name={icon}
|
99
|
+
color={type === 'primary' ? 'base' : 'highlight'}
|
100
|
+
background={type === 'primary' ? 'highlight' : undefined}
|
101
|
+
/>
|
102
|
+
<Spacer.Horizontal size="sm" />
|
103
|
+
<Paragraph weight="medium">{children}</Paragraph>
|
104
|
+
</>
|
105
|
+
)}
|
106
|
+
</div>
|
107
|
+
)
|
108
|
+
}
|
109
|
+
|
110
|
+
AddButton.propTypes = {
|
111
|
+
children: PropTypes.node.isRequired,
|
112
|
+
getStyles: PropTypes.func.isRequired,
|
113
|
+
onAdd: PropTypes.func.isRequired,
|
114
|
+
type: PropTypes.oneOf(options.types),
|
115
|
+
icon: PropTypes.oneOf(options.icons),
|
116
|
+
id: PropTypes.string,
|
117
|
+
focusHelpText: PropTypes.string,
|
118
|
+
blurHelpText: PropTypes.string,
|
119
|
+
defaultIsEditable: PropTypes.bool,
|
120
|
+
defaultIsFocused: PropTypes.bool,
|
121
|
+
defaultIsInvalid: PropTypes.bool,
|
122
|
+
defaultValue: PropTypes.string,
|
123
|
+
isInvalid: PropTypes.bool,
|
124
|
+
}
|
125
|
+
|
126
|
+
AddButton.defaultProps = {
|
127
|
+
id: '',
|
128
|
+
type: 'primary',
|
129
|
+
icon: 'plusCircle',
|
130
|
+
defaultIsEditable: false,
|
131
|
+
defaultIsFocused: false,
|
132
|
+
defaultValue: '',
|
133
|
+
onAdd: () => {},
|
134
|
+
getStyles: () => {},
|
135
|
+
}
|
136
|
+
|
137
|
+
export default withStyles(styles)(AddButton)
|
@@ -0,0 +1,128 @@
|
|
1
|
+
.add-button {
|
2
|
+
display: flex;
|
3
|
+
width: 100%;
|
4
|
+
align-items: center;
|
5
|
+
padding: 10px 12px;
|
6
|
+
border: var(--border-width-thin) dashed;
|
7
|
+
background: var(--input-background);
|
8
|
+
cursor: pointer;
|
9
|
+
user-select: none;
|
10
|
+
}
|
11
|
+
|
12
|
+
.type-primary {
|
13
|
+
height: 48px;
|
14
|
+
border-color: var(--color-font-base);
|
15
|
+
border-radius: var(--button-border-radius-sm);
|
16
|
+
}
|
17
|
+
|
18
|
+
.type-secondary {
|
19
|
+
height: 40px;
|
20
|
+
border-color: var(--color-primary);
|
21
|
+
border-radius: var(--button-border-radius-md);
|
22
|
+
}
|
23
|
+
|
24
|
+
.is-editable {
|
25
|
+
padding: 0;
|
26
|
+
border: var(--border-width-thin) solid var(--color-primary);
|
27
|
+
background: var(--color-primary);
|
28
|
+
box-shadow: 0 0 0 1px var(--color-primary);
|
29
|
+
cursor: text;
|
30
|
+
transition: box-shadow 0.2s ease;
|
31
|
+
}
|
32
|
+
|
33
|
+
.is-editable.is-focused {
|
34
|
+
background: var(--input-background);
|
35
|
+
box-shadow: 0 0 0 1px var(--color-primary), 0 0 10px 0 var(--color-primary);
|
36
|
+
}
|
37
|
+
|
38
|
+
.is-editable.is-focused.is-invalid {
|
39
|
+
animation: shake 0.8s cubic-bezier(0.36, 0.07, 0.19, 0.97) both,
|
40
|
+
fadeOutInvalidBorderColor 2s ease-out forwards,
|
41
|
+
fadeOutInvalidBoxShadow 2s ease-out forwards;
|
42
|
+
backface-visibility: hidden;
|
43
|
+
perspective: 1000px;
|
44
|
+
transform: translate3d(0, 0, 0);
|
45
|
+
}
|
46
|
+
|
47
|
+
.is-editable input {
|
48
|
+
overflow: hidden;
|
49
|
+
width: 100%;
|
50
|
+
height: 100%;
|
51
|
+
padding: 0 12px;
|
52
|
+
border: var(--border-width-thin) solid transparent;
|
53
|
+
background: var(--color-transparent);
|
54
|
+
color: var(--color-font-inverted);
|
55
|
+
font-family: var(--font-family-sans);
|
56
|
+
font-size: var(--input-font-size);
|
57
|
+
font-weight: var(--font-weight-medium);
|
58
|
+
line-height: var(--line-height-none);
|
59
|
+
text-overflow: ellipsis;
|
60
|
+
white-space: nowrap;
|
61
|
+
}
|
62
|
+
|
63
|
+
.is-editable.is-focused input {
|
64
|
+
color: var(--color-font-base);
|
65
|
+
}
|
66
|
+
|
67
|
+
.is-editable input:focus {
|
68
|
+
outline: none;
|
69
|
+
}
|
70
|
+
|
71
|
+
.edit-container {
|
72
|
+
display: flex;
|
73
|
+
width: 100%;
|
74
|
+
height: 100%;
|
75
|
+
align-items: center;
|
76
|
+
justify-content: space-between;
|
77
|
+
}
|
78
|
+
|
79
|
+
.edit-container :global(.help-text) {
|
80
|
+
width: 100%;
|
81
|
+
max-width: max-content;
|
82
|
+
}
|
83
|
+
|
84
|
+
@keyframes fadeOutInvalidBoxShadow {
|
85
|
+
0%,
|
86
|
+
50% {
|
87
|
+
box-shadow: 0 0 0 1px var(--color-rose-500),
|
88
|
+
0 0 10px 0 var(--color-rose-500);
|
89
|
+
}
|
90
|
+
|
91
|
+
100% {
|
92
|
+
box-shadow: 0 0 0 1px var(--color-primary), 0 0 10px 0 var(--color-primary);
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
@keyframes fadeOutInvalidBorderColor {
|
97
|
+
0%,
|
98
|
+
50% {
|
99
|
+
border-color: var(--color-rose-500);
|
100
|
+
}
|
101
|
+
|
102
|
+
100% {
|
103
|
+
border-color: var(--color-primary);
|
104
|
+
}
|
105
|
+
}
|
106
|
+
|
107
|
+
@keyframes shake {
|
108
|
+
10%,
|
109
|
+
90% {
|
110
|
+
transform: translate3d(-1px, 0, 0);
|
111
|
+
}
|
112
|
+
|
113
|
+
20%,
|
114
|
+
80% {
|
115
|
+
transform: translate3d(2px, 0, 0);
|
116
|
+
}
|
117
|
+
|
118
|
+
30%,
|
119
|
+
50%,
|
120
|
+
70% {
|
121
|
+
transform: translate3d(-4px, 0, 0);
|
122
|
+
}
|
123
|
+
|
124
|
+
40%,
|
125
|
+
60% {
|
126
|
+
transform: translate3d(4px, 0, 0);
|
127
|
+
}
|
128
|
+
}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
import { AddButton, options, styles } from '.'
|
2
|
+
import {
|
3
|
+
getTemplate,
|
4
|
+
getListTemplate,
|
5
|
+
getOptionsArgTypes,
|
6
|
+
} from '../../helpers/storybook'
|
7
|
+
|
8
|
+
const Template = getTemplate(AddButton, styles)
|
9
|
+
const ListTemplate = getListTemplate(AddButton, styles)
|
10
|
+
|
11
|
+
export default {
|
12
|
+
title: 'Molecules/AddButton',
|
13
|
+
component: AddButton,
|
14
|
+
args: {
|
15
|
+
children: "Caves they've pick stealth Dwarf?",
|
16
|
+
},
|
17
|
+
argTypes: {
|
18
|
+
type: getOptionsArgTypes(options.types),
|
19
|
+
icon: getOptionsArgTypes(options.icons),
|
20
|
+
},
|
21
|
+
}
|
22
|
+
|
23
|
+
export const Default = Template.bind({})
|
24
|
+
|
25
|
+
export const Types = ListTemplate.bind({})
|
26
|
+
Types.args = { items: options.types.map((type) => ({ type })) }
|
27
|
+
|
28
|
+
export const EditMode = Template.bind({})
|
29
|
+
EditMode.args = {
|
30
|
+
defaultValue: 'Fixed caught squash wax Silvan sweet-taking keeps.',
|
31
|
+
defaultIsEditable: true,
|
32
|
+
}
|
33
|
+
|
34
|
+
export const Invalid = Template.bind({})
|
35
|
+
Invalid.args = {
|
36
|
+
defaultIsInvalid: true,
|
37
|
+
defaultIsEditable: true,
|
38
|
+
defaultIsFocused: true,
|
39
|
+
}
|
40
|
+
|
41
|
+
export const HelpText = Template.bind({})
|
42
|
+
HelpText.args = {
|
43
|
+
defaultValue: "Understand bravely halfling's rank balls.",
|
44
|
+
defaultIsEditable: true,
|
45
|
+
focusHelpText: 'Fly, you fools!',
|
46
|
+
blurHelpText: "Morgul-rats cripples you'll?",
|
47
|
+
}
|
@@ -0,0 +1,326 @@
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
2
|
+
|
3
|
+
exports[`Storyshots Molecules/AddButton Default 1`] = `
|
4
|
+
<div
|
5
|
+
style={
|
6
|
+
Object {
|
7
|
+
"alignContent": "flex-start",
|
8
|
+
"display": "flex",
|
9
|
+
"flexDirection": "column",
|
10
|
+
"flexWrap": "wrap",
|
11
|
+
"gap": "10px 30px",
|
12
|
+
"height": "100%",
|
13
|
+
"justifyContent": "flex-start",
|
14
|
+
"maxHeight": "auto",
|
15
|
+
}
|
16
|
+
}
|
17
|
+
>
|
18
|
+
<div
|
19
|
+
className="add-button type-primary"
|
20
|
+
id="-add-button"
|
21
|
+
onClick={[Function]}
|
22
|
+
>
|
23
|
+
<div
|
24
|
+
className="icon color-base size-md background-highlight"
|
25
|
+
style={
|
26
|
+
Object {
|
27
|
+
"height": 35,
|
28
|
+
"width": 35,
|
29
|
+
}
|
30
|
+
}
|
31
|
+
>
|
32
|
+
<svg
|
33
|
+
height={35}
|
34
|
+
viewBox="0 0 20 20"
|
35
|
+
width={35}
|
36
|
+
xmlns="http://www.w3.org/2000/svg"
|
37
|
+
>
|
38
|
+
<path
|
39
|
+
clipRule="evenodd"
|
40
|
+
d="M10 20C4.48612 20 0 15.5139 0 10C0 4.48612 4.48612 0 10 0C15.5139 0 20 4.48612 20 10C20 15.5139 15.5139 20 10 20ZM10 1.09864C5.09155 1.09864 1.09864 5.09155 1.09864 10C1.09864 14.9084 5.09155 18.9014 10 18.9014C14.9084 18.9014 18.9014 14.9084 18.9014 10C18.9014 5.09155 14.9084 1.09864 10 1.09864Z"
|
41
|
+
fillRule="evenodd"
|
42
|
+
/>
|
43
|
+
<path
|
44
|
+
clipRule="evenodd"
|
45
|
+
d="M4.68396 9.4093H15.316V10.5906H4.68396V9.4093Z"
|
46
|
+
fillRule="evenodd"
|
47
|
+
/>
|
48
|
+
<path
|
49
|
+
clipRule="evenodd"
|
50
|
+
d="M9.40942 4.68396H10.5908V15.316H9.40942V4.68396Z"
|
51
|
+
fillRule="evenodd"
|
52
|
+
/>
|
53
|
+
</svg>
|
54
|
+
</div>
|
55
|
+
<div
|
56
|
+
className="spacer horizontal"
|
57
|
+
style={
|
58
|
+
Object {
|
59
|
+
"height": "100%",
|
60
|
+
"maxHeight": "auto",
|
61
|
+
"width": 15,
|
62
|
+
}
|
63
|
+
}
|
64
|
+
/>
|
65
|
+
<p
|
66
|
+
className="paragraph color-base size-md weight-medium"
|
67
|
+
>
|
68
|
+
Caves they've pick stealth Dwarf?
|
69
|
+
</p>
|
70
|
+
</div>
|
71
|
+
</div>
|
72
|
+
`;
|
73
|
+
|
74
|
+
exports[`Storyshots Molecules/AddButton Edit Mode 1`] = `
|
75
|
+
<div
|
76
|
+
style={
|
77
|
+
Object {
|
78
|
+
"alignContent": "flex-start",
|
79
|
+
"display": "flex",
|
80
|
+
"flexDirection": "column",
|
81
|
+
"flexWrap": "wrap",
|
82
|
+
"gap": "10px 30px",
|
83
|
+
"height": "100%",
|
84
|
+
"justifyContent": "flex-start",
|
85
|
+
"maxHeight": "auto",
|
86
|
+
}
|
87
|
+
}
|
88
|
+
>
|
89
|
+
<div
|
90
|
+
className="add-button type-primary is-editable"
|
91
|
+
id="-add-button"
|
92
|
+
onClick={[Function]}
|
93
|
+
>
|
94
|
+
<div
|
95
|
+
className="edit-container"
|
96
|
+
>
|
97
|
+
<input
|
98
|
+
autoFocus={false}
|
99
|
+
id="-add-button-input"
|
100
|
+
onBlur={[Function]}
|
101
|
+
onChange={[Function]}
|
102
|
+
onFocus={[Function]}
|
103
|
+
onKeyDown={[Function]}
|
104
|
+
type="text"
|
105
|
+
value="Fixed caught squash wax Silvan sweet-taking keeps."
|
106
|
+
/>
|
107
|
+
</div>
|
108
|
+
</div>
|
109
|
+
</div>
|
110
|
+
`;
|
111
|
+
|
112
|
+
exports[`Storyshots Molecules/AddButton Help Text 1`] = `
|
113
|
+
<div
|
114
|
+
style={
|
115
|
+
Object {
|
116
|
+
"alignContent": "flex-start",
|
117
|
+
"display": "flex",
|
118
|
+
"flexDirection": "column",
|
119
|
+
"flexWrap": "wrap",
|
120
|
+
"gap": "10px 30px",
|
121
|
+
"height": "100%",
|
122
|
+
"justifyContent": "flex-start",
|
123
|
+
"maxHeight": "auto",
|
124
|
+
}
|
125
|
+
}
|
126
|
+
>
|
127
|
+
<div
|
128
|
+
className="add-button type-primary is-editable"
|
129
|
+
id="-add-button"
|
130
|
+
onClick={[Function]}
|
131
|
+
>
|
132
|
+
<div
|
133
|
+
className="edit-container"
|
134
|
+
>
|
135
|
+
<input
|
136
|
+
autoFocus={false}
|
137
|
+
id="-add-button-input"
|
138
|
+
onBlur={[Function]}
|
139
|
+
onChange={[Function]}
|
140
|
+
onFocus={[Function]}
|
141
|
+
onKeyDown={[Function]}
|
142
|
+
type="text"
|
143
|
+
value="Understand bravely halfling's rank balls."
|
144
|
+
/>
|
145
|
+
<p
|
146
|
+
className="help-text paragraph color-inverted size-sm weight-normal"
|
147
|
+
>
|
148
|
+
Morgul-rats cripples you'll?
|
149
|
+
</p>
|
150
|
+
<div
|
151
|
+
className="spacer horizontal"
|
152
|
+
style={
|
153
|
+
Object {
|
154
|
+
"height": "100%",
|
155
|
+
"maxHeight": "auto",
|
156
|
+
"width": 15,
|
157
|
+
}
|
158
|
+
}
|
159
|
+
/>
|
160
|
+
</div>
|
161
|
+
</div>
|
162
|
+
</div>
|
163
|
+
`;
|
164
|
+
|
165
|
+
exports[`Storyshots Molecules/AddButton Invalid 1`] = `
|
166
|
+
<div
|
167
|
+
style={
|
168
|
+
Object {
|
169
|
+
"alignContent": "flex-start",
|
170
|
+
"display": "flex",
|
171
|
+
"flexDirection": "column",
|
172
|
+
"flexWrap": "wrap",
|
173
|
+
"gap": "10px 30px",
|
174
|
+
"height": "100%",
|
175
|
+
"justifyContent": "flex-start",
|
176
|
+
"maxHeight": "auto",
|
177
|
+
}
|
178
|
+
}
|
179
|
+
>
|
180
|
+
<div
|
181
|
+
className="add-button type-primary is-editable is-focused is-invalid"
|
182
|
+
id="-add-button"
|
183
|
+
onClick={[Function]}
|
184
|
+
>
|
185
|
+
<div
|
186
|
+
className="edit-container"
|
187
|
+
>
|
188
|
+
<input
|
189
|
+
autoFocus={false}
|
190
|
+
id="-add-button-input"
|
191
|
+
onBlur={[Function]}
|
192
|
+
onChange={[Function]}
|
193
|
+
onFocus={[Function]}
|
194
|
+
onKeyDown={[Function]}
|
195
|
+
type="text"
|
196
|
+
value=""
|
197
|
+
/>
|
198
|
+
|
199
|
+
</div>
|
200
|
+
</div>
|
201
|
+
</div>
|
202
|
+
`;
|
203
|
+
|
204
|
+
exports[`Storyshots Molecules/AddButton Types 1`] = `
|
205
|
+
<div
|
206
|
+
style={
|
207
|
+
Object {
|
208
|
+
"alignContent": "flex-start",
|
209
|
+
"display": "flex",
|
210
|
+
"flexDirection": "column",
|
211
|
+
"flexWrap": "wrap",
|
212
|
+
"gap": "10px 30px",
|
213
|
+
"height": "100%",
|
214
|
+
"justifyContent": "flex-start",
|
215
|
+
"maxHeight": "auto",
|
216
|
+
}
|
217
|
+
}
|
218
|
+
>
|
219
|
+
<div
|
220
|
+
className="add-button type-primary"
|
221
|
+
id="-add-button"
|
222
|
+
onClick={[Function]}
|
223
|
+
>
|
224
|
+
<div
|
225
|
+
className="icon color-base size-md background-highlight"
|
226
|
+
style={
|
227
|
+
Object {
|
228
|
+
"height": 35,
|
229
|
+
"width": 35,
|
230
|
+
}
|
231
|
+
}
|
232
|
+
>
|
233
|
+
<svg
|
234
|
+
height={35}
|
235
|
+
viewBox="0 0 20 20"
|
236
|
+
width={35}
|
237
|
+
xmlns="http://www.w3.org/2000/svg"
|
238
|
+
>
|
239
|
+
<path
|
240
|
+
clipRule="evenodd"
|
241
|
+
d="M10 20C4.48612 20 0 15.5139 0 10C0 4.48612 4.48612 0 10 0C15.5139 0 20 4.48612 20 10C20 15.5139 15.5139 20 10 20ZM10 1.09864C5.09155 1.09864 1.09864 5.09155 1.09864 10C1.09864 14.9084 5.09155 18.9014 10 18.9014C14.9084 18.9014 18.9014 14.9084 18.9014 10C18.9014 5.09155 14.9084 1.09864 10 1.09864Z"
|
242
|
+
fillRule="evenodd"
|
243
|
+
/>
|
244
|
+
<path
|
245
|
+
clipRule="evenodd"
|
246
|
+
d="M4.68396 9.4093H15.316V10.5906H4.68396V9.4093Z"
|
247
|
+
fillRule="evenodd"
|
248
|
+
/>
|
249
|
+
<path
|
250
|
+
clipRule="evenodd"
|
251
|
+
d="M9.40942 4.68396H10.5908V15.316H9.40942V4.68396Z"
|
252
|
+
fillRule="evenodd"
|
253
|
+
/>
|
254
|
+
</svg>
|
255
|
+
</div>
|
256
|
+
<div
|
257
|
+
className="spacer horizontal"
|
258
|
+
style={
|
259
|
+
Object {
|
260
|
+
"height": "100%",
|
261
|
+
"maxHeight": "auto",
|
262
|
+
"width": 15,
|
263
|
+
}
|
264
|
+
}
|
265
|
+
/>
|
266
|
+
<p
|
267
|
+
className="paragraph color-base size-md weight-medium"
|
268
|
+
>
|
269
|
+
Caves they've pick stealth Dwarf?
|
270
|
+
</p>
|
271
|
+
</div>
|
272
|
+
<div
|
273
|
+
className="add-button type-secondary"
|
274
|
+
id="-add-button"
|
275
|
+
onClick={[Function]}
|
276
|
+
>
|
277
|
+
<div
|
278
|
+
className="icon color-highlight size-md"
|
279
|
+
style={
|
280
|
+
Object {
|
281
|
+
"height": 35,
|
282
|
+
"width": 35,
|
283
|
+
}
|
284
|
+
}
|
285
|
+
>
|
286
|
+
<svg
|
287
|
+
height={35}
|
288
|
+
viewBox="0 0 20 20"
|
289
|
+
width={35}
|
290
|
+
xmlns="http://www.w3.org/2000/svg"
|
291
|
+
>
|
292
|
+
<path
|
293
|
+
clipRule="evenodd"
|
294
|
+
d="M10 20C4.48612 20 0 15.5139 0 10C0 4.48612 4.48612 0 10 0C15.5139 0 20 4.48612 20 10C20 15.5139 15.5139 20 10 20ZM10 1.09864C5.09155 1.09864 1.09864 5.09155 1.09864 10C1.09864 14.9084 5.09155 18.9014 10 18.9014C14.9084 18.9014 18.9014 14.9084 18.9014 10C18.9014 5.09155 14.9084 1.09864 10 1.09864Z"
|
295
|
+
fillRule="evenodd"
|
296
|
+
/>
|
297
|
+
<path
|
298
|
+
clipRule="evenodd"
|
299
|
+
d="M4.68396 9.4093H15.316V10.5906H4.68396V9.4093Z"
|
300
|
+
fillRule="evenodd"
|
301
|
+
/>
|
302
|
+
<path
|
303
|
+
clipRule="evenodd"
|
304
|
+
d="M9.40942 4.68396H10.5908V15.316H9.40942V4.68396Z"
|
305
|
+
fillRule="evenodd"
|
306
|
+
/>
|
307
|
+
</svg>
|
308
|
+
</div>
|
309
|
+
<div
|
310
|
+
className="spacer horizontal"
|
311
|
+
style={
|
312
|
+
Object {
|
313
|
+
"height": "100%",
|
314
|
+
"maxHeight": "auto",
|
315
|
+
"width": 15,
|
316
|
+
}
|
317
|
+
}
|
318
|
+
/>
|
319
|
+
<p
|
320
|
+
className="paragraph color-base size-md weight-medium"
|
321
|
+
>
|
322
|
+
Caves they've pick stealth Dwarf?
|
323
|
+
</p>
|
324
|
+
</div>
|
325
|
+
</div>
|
326
|
+
`;
|
@@ -0,0 +1,58 @@
|
|
1
|
+
import keyboardCodes from '../../utils/keyboardCodes'
|
2
|
+
import isEmpty from '../../utils/isEmpty'
|
3
|
+
|
4
|
+
const setIsInvalidAnimation = ({ setIsInvalid }) => {
|
5
|
+
setIsInvalid(false)
|
6
|
+
setTimeout(() => setIsInvalid(true), 0)
|
7
|
+
}
|
8
|
+
|
9
|
+
export const handleClick = ({ setIsEditable, inputRef }) => () => {
|
10
|
+
setIsEditable(true)
|
11
|
+
inputRef?.current?.focus()
|
12
|
+
}
|
13
|
+
|
14
|
+
export const handleChange = ({ setInputValue, setIsInvalid }) => (event) => {
|
15
|
+
const { value } = event.currentTarget
|
16
|
+
setIsInvalid(false)
|
17
|
+
setInputValue(value)
|
18
|
+
}
|
19
|
+
|
20
|
+
export const handleKeyDown = ({
|
21
|
+
onAdd,
|
22
|
+
setIsEditable,
|
23
|
+
setInputValue,
|
24
|
+
setIsInvalid,
|
25
|
+
inputValue,
|
26
|
+
}) => (event) => {
|
27
|
+
if (event.key === keyboardCodes.ENTER) {
|
28
|
+
onAdd({ value: inputValue })
|
29
|
+
setInputValue('')
|
30
|
+
setIsEditable(false)
|
31
|
+
|
32
|
+
if (isEmpty(inputValue)) {
|
33
|
+
setIsInvalidAnimation({ setIsInvalid })
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
if (event.key === keyboardCodes.ESC) {
|
38
|
+
setInputValue('')
|
39
|
+
setIsEditable(false)
|
40
|
+
setIsInvalid(false)
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
export const handleBlur = ({
|
45
|
+
inputValue,
|
46
|
+
setIsEditable,
|
47
|
+
setIsFocused,
|
48
|
+
setIsInvalid,
|
49
|
+
}) => () => {
|
50
|
+
setIsFocused(false)
|
51
|
+
setIsInvalid(false)
|
52
|
+
!inputValue && setIsEditable(false)
|
53
|
+
}
|
54
|
+
|
55
|
+
export const handleFocus = ({ setIsFocused }) => (event) => {
|
56
|
+
event && event.currentTarget.select()
|
57
|
+
setIsFocused(true)
|
58
|
+
}
|