@pareto-engineering/design-system 2.0.0-alpha.60 → 2.0.0-alpha.62

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.
Files changed (39) hide show
  1. package/dist/cjs/a/Label/Label.js +87 -0
  2. package/dist/cjs/a/Label/index.js +15 -0
  3. package/dist/cjs/a/Label/styles.scss +34 -0
  4. package/dist/cjs/a/index.js +9 -1
  5. package/dist/cjs/f/FormInput/FormInput.js +6 -0
  6. package/dist/cjs/f/fields/Checkbox/Checkbox.js +117 -0
  7. package/dist/cjs/f/fields/Checkbox/index.js +15 -0
  8. package/dist/cjs/f/fields/Checkbox/styles.scss +14 -0
  9. package/dist/cjs/f/fields/ChoicesInput/ChoicesInput.js +1 -1
  10. package/dist/cjs/f/fields/ChoicesInput/common/Choice/Choice.js +2 -5
  11. package/dist/cjs/f/fields/index.js +9 -1
  12. package/dist/es/a/Label/Label.js +71 -0
  13. package/dist/es/a/Label/index.js +2 -0
  14. package/dist/es/a/Label/styles.scss +34 -0
  15. package/dist/es/a/index.js +2 -1
  16. package/dist/es/f/FormInput/FormInput.js +7 -1
  17. package/dist/es/f/fields/Checkbox/Checkbox.js +99 -0
  18. package/dist/es/f/fields/Checkbox/index.js +2 -0
  19. package/dist/es/f/fields/Checkbox/styles.scss +14 -0
  20. package/dist/es/f/fields/ChoicesInput/ChoicesInput.js +1 -1
  21. package/dist/es/f/fields/ChoicesInput/common/Choice/Choice.js +2 -5
  22. package/dist/es/f/fields/index.js +2 -1
  23. package/package.json +1 -1
  24. package/src/__snapshots__/Storyshots.test.js.snap +1940 -1352
  25. package/src/stories/a/Label.stories.jsx +49 -0
  26. package/src/stories/f/Checkbox.stories.jsx +95 -0
  27. package/src/stories/f/ChoicesInput.stories.jsx +10 -36
  28. package/src/stories/f/FormInput.stories.jsx +5 -0
  29. package/src/ui/a/Label/Label.jsx +93 -0
  30. package/src/ui/a/Label/index.js +2 -0
  31. package/src/ui/a/Label/styles.scss +34 -0
  32. package/src/ui/a/index.js +1 -0
  33. package/src/ui/f/FormInput/FormInput.jsx +11 -0
  34. package/src/ui/f/fields/Checkbox/Checkbox.jsx +118 -0
  35. package/src/ui/f/fields/Checkbox/index.js +2 -0
  36. package/src/ui/f/fields/Checkbox/styles.scss +14 -0
  37. package/src/ui/f/fields/ChoicesInput/ChoicesInput.jsx +1 -1
  38. package/src/ui/f/fields/ChoicesInput/common/Choice/Choice.jsx +2 -10
  39. package/src/ui/f/fields/index.js +1 -0
@@ -0,0 +1,49 @@
1
+ /* @pareto-engineering/generator-front 1.0.12 */
2
+ import * as React from 'react'
3
+ import { Label } from 'ui'
4
+ import { ALL_COLORS } from 'stories/colors'
5
+
6
+ export default {
7
+ title :'a/Label',
8
+ component :Label,
9
+ subcomponents:{
10
+ // Item:ColumnLabel.Item
11
+ },
12
+ decorators:[
13
+ // storyfn => <div className="">{ storyfn() }</div>,
14
+ ],
15
+ argTypes:{
16
+ color :{ control: { type: 'select', options: ALL_COLORS } },
17
+ isCompact:{ control: { type: 'boolean' } },
18
+ isGhost :{ control: { type: 'boolean' } },
19
+ },
20
+ }
21
+
22
+ const Template = (args) => <Label {...args} />
23
+
24
+ export const Base = Template.bind({})
25
+ Base.args = {
26
+ children:'Label Value',
27
+ }
28
+
29
+ const MultiTemplate = (args) => ALL_COLORS.map((color) => (
30
+ <Label {...args} color={color} key={color}>
31
+ This is a
32
+ {' '}
33
+ {color}
34
+ {' '}
35
+ label
36
+ </Label>
37
+ ))
38
+
39
+ export const Normal = MultiTemplate.bind({})
40
+
41
+ export const Ghost = MultiTemplate.bind({})
42
+ Ghost.args = {
43
+ isGhost:true,
44
+ }
45
+
46
+ export const Compact = MultiTemplate.bind({})
47
+ Compact.args = {
48
+ isCompact:true,
49
+ }
@@ -0,0 +1,95 @@
1
+ /* @pareto-engineering/generator-front 1.0.12 */
2
+ import * as React from 'react'
3
+
4
+ import { useEffect } from 'react'
5
+
6
+ import { Formik, Form, useField } from 'formik'
7
+
8
+ import { Checkbox, FormDebugger } from 'ui'
9
+
10
+ export default {
11
+ title :'f/fields/Checkbox',
12
+ component :Checkbox,
13
+ subcomponents:{
14
+ // Item:Checkbox.Item
15
+ },
16
+ decorators:[
17
+ // storyfn => <div className="">{ storyfn() }</div>,
18
+ (storyfn) => (
19
+ <Formik
20
+ initialValues={{}}
21
+ >
22
+ <Form>
23
+
24
+ { storyfn() }
25
+ </Form>
26
+ </Formik>
27
+ ),
28
+ ],
29
+ argTypes:{
30
+ label :{ control: 'text' },
31
+ description :{ control: 'text' },
32
+ defaultValue:{ control: 'boolean' },
33
+ disabled :{ control: 'boolean' },
34
+ optional :{ control: 'boolean' },
35
+ },
36
+ }
37
+
38
+ // eslint-disable-next-line react/prop-types
39
+ const Template = ({ defaultValue, ...args }) => {
40
+ const Content = () => {
41
+ const { name } = args
42
+ const [, , helpers] = useField(name)
43
+ const { setValue } = helpers
44
+
45
+ useEffect(() => {
46
+ if (defaultValue) {
47
+ setValue(defaultValue)
48
+ }
49
+ }, [defaultValue])
50
+
51
+ return (
52
+ <>
53
+ <Checkbox {...args} />
54
+ <FormDebugger />
55
+ </>
56
+ )
57
+ }
58
+
59
+ return <Content />
60
+ }
61
+
62
+ export const Base = Template.bind({})
63
+ Base.args = {
64
+ name:'urgent',
65
+ }
66
+
67
+ export const WithLabel = Template.bind({})
68
+ WithLabel.args = {
69
+ ...Base.args,
70
+ label:'Urgent',
71
+ }
72
+
73
+ export const WithDescription = Template.bind({})
74
+ WithDescription.args = {
75
+ ...Base.args,
76
+ description:'Click on the checkbox',
77
+ }
78
+
79
+ export const WithDefaultFormikValue = Template.bind({})
80
+ WithDefaultFormikValue.args = {
81
+ ...Base.args,
82
+ defaultValue:true,
83
+ }
84
+
85
+ export const Disabled = Template.bind({})
86
+ Disabled.args = {
87
+ ...Base.args,
88
+ disabled:true,
89
+ }
90
+
91
+ export const Optional = Template.bind({})
92
+ Optional.args = {
93
+ ...Base.args,
94
+ optional:true,
95
+ }
@@ -1,8 +1,8 @@
1
1
  /* @pareto-engineering/generator-front 1.0.12 */
2
2
  import * as React from 'react'
3
- import { useEffect } from 'react'
3
+
4
4
  import { ChoicesInput, FormDebugger } from 'ui'
5
- import { Formik, Form, useField } from 'formik'
5
+ import { Formik, Form } from 'formik'
6
6
 
7
7
  export default {
8
8
  title :'f/fields/ChoicesInput',
@@ -29,6 +29,14 @@ export default {
29
29
  },
30
30
  }
31
31
 
32
+ const Template = (args) => (
33
+ <>
34
+ <ChoicesInput {...args} />
35
+ <FormDebugger />
36
+ </>
37
+ )
38
+
39
+ export const Base = Template.bind({})
32
40
  const optionsMap = [
33
41
  {
34
42
  value:'red',
@@ -64,52 +72,18 @@ const optionsMap = [
64
72
  },
65
73
  ]
66
74
 
67
- // eslint-disable-next-line react/prop-types
68
- const Template = ({ defaultValue, ...args }) => {
69
- const Content = () => {
70
- const [, , helpers] = useField(args.name)
71
- const { setValue } = helpers
72
-
73
- useEffect(() => {
74
- setValue(defaultValue)
75
- }, [])
76
-
77
- return (
78
- <>
79
- <ChoicesInput {...args} />
80
- <FormDebugger />
81
- </>
82
- )
83
- }
84
- return <Content />
85
- }
86
-
87
- export const Base = Template.bind({})
88
75
  Base.args = {
89
76
  id :'colors',
90
77
  options:optionsMap,
91
78
  name :'color',
92
79
  }
93
80
 
94
- export const WithDefaultFormikValue = Template.bind({})
95
- WithDefaultFormikValue.args = {
96
- ...Base.args,
97
- defaultValue:'red',
98
- }
99
-
100
81
  export const Multiple = Template.bind({})
101
82
  Multiple.args = {
102
83
  ...Base.args,
103
84
  multiple:true,
104
85
  }
105
86
 
106
- export const MultipleWithDefaultFormikValue = Template.bind({})
107
- MultipleWithDefaultFormikValue.args = {
108
- ...Base.args,
109
- multiple :true,
110
- defaultValue:['brown', 'violet'],
111
- }
112
-
113
87
  export const MultipleWithGrid = Template.bind({})
114
88
  MultipleWithGrid.args = {
115
89
  ...Base.args,
@@ -62,6 +62,11 @@ export const Base = () => {
62
62
  name :'description',
63
63
  label:'Describe yourself in a few sentences',
64
64
  },
65
+ {
66
+ type :'checkbox',
67
+ name :'urgent',
68
+ label:'Urgent',
69
+ },
65
70
  {
66
71
  type :'choices',
67
72
  name :'colors',
@@ -0,0 +1,93 @@
1
+ /* @pareto-engineering/generator-front 1.0.12 */
2
+ import * as React from 'react'
3
+
4
+ import { useLayoutEffect } from 'react'
5
+
6
+ import PropTypes from 'prop-types'
7
+
8
+ import styleNames from '@pareto-engineering/bem'
9
+
10
+ // Local Definitions
11
+
12
+ const baseClassName = styleNames.base
13
+
14
+ const componentClassName = 'label'
15
+
16
+ /**
17
+ * This is the component description.
18
+ */
19
+ const Label = ({
20
+ id,
21
+ className:userClassName,
22
+ style,
23
+ children,
24
+ color,
25
+ isCompact,
26
+ isGhost,
27
+ }) => {
28
+ useLayoutEffect(() => {
29
+ import('./styles.scss')
30
+ }, [])
31
+
32
+ return (
33
+ <div
34
+ id={id}
35
+ className={[
36
+ baseClassName,
37
+ componentClassName,
38
+ userClassName,
39
+ `x-${color}`,
40
+ isCompact && styleNames.modifierCompact,
41
+ isGhost && styleNames.modifierGhost,
42
+ ]
43
+ .filter((e) => e)
44
+ .join(' ')}
45
+ style={style}
46
+ >
47
+ {children}
48
+ </div>
49
+ )
50
+ }
51
+
52
+ Label.propTypes = {
53
+ /**
54
+ * The HTML id for this element
55
+ */
56
+ id:PropTypes.string,
57
+
58
+ /**
59
+ * The HTML class names for this element
60
+ */
61
+ className:PropTypes.string,
62
+
63
+ /**
64
+ * The React-written, css properties for this element.
65
+ */
66
+ style:PropTypes.objectOf(PropTypes.string),
67
+
68
+ /**
69
+ * Whether the button has the ghost style
70
+ */
71
+ isGhost:PropTypes.bool,
72
+
73
+ /**
74
+ * Whether the button is compact
75
+ */
76
+ isCompact:PropTypes.bool,
77
+
78
+ /**
79
+ * The default font color to display for the label
80
+ */
81
+ color:PropTypes.string,
82
+
83
+ /**
84
+ * The children JSX
85
+ */
86
+ children:PropTypes.node,
87
+ }
88
+
89
+ Label.defaultProps = {
90
+ color:'main1',
91
+ }
92
+
93
+ export default Label
@@ -0,0 +1,2 @@
1
+ /* @pareto-engineering/generator-front 1.0.12 */
2
+ export { default as Label } from './Label'
@@ -0,0 +1,34 @@
1
+ /* @pareto-engineering/generator-front 1.0.12 */
2
+ @use "@pareto-engineering/bem";
3
+
4
+ $default-padding-bottom: .4em;
5
+ $default-padding-side: .7em;
6
+ $default-padding-top: .5em;
7
+
8
+ $compact-padding: $default-padding-top*.8 $default-padding-side*.8 $default-padding-bottom*.8;
9
+ $default-padding: $default-padding-top $default-padding-side $default-padding-bottom;
10
+
11
+ $default-color: primary;
12
+ $default-image-size: 2em;
13
+ $default-font-size: calc(1 em * var(--s-1));
14
+
15
+ .#{bem.$base}.label{
16
+ align-items: center;
17
+ background: var(--x, var(--#{$default-color}));
18
+ border-radius: 3em;
19
+ color: var(--on-x, var(--on-#{$default-color}));
20
+ display: inline-flex;
21
+ font-size: $default-font-size;
22
+ padding: $default-padding;
23
+ white-space: nowrap;
24
+
25
+ &.#{bem.$modifier-compact} {
26
+ padding: $compact-padding;
27
+ }
28
+
29
+ &.#{bem.$modifier-ghost} {
30
+ background: transparent;
31
+ border: 1px solid var(--x, var(--#{$default-color}));
32
+ color: var(--x, var(--#{$default-color}));
33
+ }
34
+ }
package/src/ui/a/index.js CHANGED
@@ -30,3 +30,4 @@ export { BackgroundGradient } from './BackgroundGradient'
30
30
  export { ContentTree } from './ContentTree'
31
31
  export { Popover } from './Popover'
32
32
  export { Alert } from './Alert'
33
+ export { Label } from './Label'
@@ -13,6 +13,7 @@ import {
13
13
  QueryCombobox,
14
14
  QuerySelect,
15
15
  RatingsInput,
16
+ Checkbox,
16
17
  } from '../fields'
17
18
 
18
19
  // Local Definitions
@@ -94,6 +95,16 @@ const FormInput = ({
94
95
  />
95
96
  )
96
97
  }
98
+
99
+ if (type === 'checkbox') {
100
+ return (
101
+ <Checkbox
102
+ className={newClassName}
103
+ {...otherProps}
104
+ />
105
+ )
106
+ }
107
+
97
108
  if (extraTypes?.[type]) {
98
109
  const Component = extraTypes[type]
99
110
  return (
@@ -0,0 +1,118 @@
1
+ /* @pareto-engineering/generator-front 1.0.12 */
2
+ import * as React from 'react'
3
+
4
+ import { useLayoutEffect } from 'react'
5
+
6
+ import PropTypes from 'prop-types'
7
+
8
+ import styleNames from '@pareto-engineering/bem'
9
+
10
+ import { useField } from 'formik'
11
+
12
+ import { FormLabel, FormDescription } from '../../common'
13
+
14
+ // Local Definitions
15
+
16
+ const baseClassName = styleNames.base
17
+
18
+ const componentClassName = 'checkbox'
19
+
20
+ /**
21
+ * This is the component description.
22
+ */
23
+ const Checkbox = ({
24
+ id,
25
+ className:userClassName,
26
+ style,
27
+ name,
28
+ label,
29
+ description,
30
+ disabled,
31
+ optional,
32
+ // ...otherProps
33
+ }) => {
34
+ useLayoutEffect(() => {
35
+ import('./styles.scss')
36
+ }, [])
37
+
38
+ const [field] = useField({ name, type: 'checkbox' })
39
+
40
+ return (
41
+ <div
42
+ id={id}
43
+ className={[
44
+
45
+ baseClassName,
46
+
47
+ componentClassName,
48
+ userClassName,
49
+ ]
50
+ .filter((e) => e)
51
+ .join(' ')}
52
+ style={style}
53
+ // {...otherProps}
54
+ >
55
+ {label && (
56
+ <FormLabel name={name} optional={optional}>
57
+ {label}
58
+ </FormLabel>
59
+ )}
60
+ <input
61
+ id={name}
62
+ className="input"
63
+ type="checkbox"
64
+ disabled={disabled}
65
+ {...field}
66
+ />
67
+ <FormDescription className="v50 mt-v s-1" description={description} name={name} />
68
+ </div>
69
+ )
70
+ }
71
+
72
+ Checkbox.propTypes = {
73
+ /**
74
+ * The HTML id for this element
75
+ */
76
+ id:PropTypes.string,
77
+
78
+ /**
79
+ * The HTML class names for this element
80
+ */
81
+ className:PropTypes.string,
82
+
83
+ /**
84
+ * The React-written, css properties for this element.
85
+ */
86
+ style:PropTypes.objectOf(PropTypes.string),
87
+
88
+ /**
89
+ * The input name (html - and Formik state)
90
+ */
91
+ name:PropTypes.string.isRequired,
92
+
93
+ /**
94
+ * The Input description to guide the user if it's not obvious
95
+ */
96
+ description:PropTypes.string,
97
+
98
+ /**
99
+ * Whether the input should be disabled
100
+ */
101
+ disabled:PropTypes.bool,
102
+
103
+ /**
104
+ * The input label
105
+ */
106
+ label:PropTypes.string,
107
+
108
+ /**
109
+ * Whether the input should have an optional tag
110
+ */
111
+ optional:PropTypes.bool,
112
+ }
113
+
114
+ Checkbox.defaultProps = {
115
+ disabled:false,
116
+ }
117
+
118
+ export default Checkbox
@@ -0,0 +1,2 @@
1
+ /* @pareto-engineering/generator-front 1.0.12 */
2
+ export { default as Checkbox } from './Checkbox'
@@ -0,0 +1,14 @@
1
+ /* @pareto-engineering/generator-front 1.0.12 */
2
+ @use "@pareto-engineering/bem";
3
+
4
+ $default-margin: 1em;
5
+
6
+ .#{bem.$base}.checkbox {
7
+ display: flex;
8
+ flex-direction: column;
9
+ align-items: flex-start;
10
+
11
+ .#{bem.$base}.label {
12
+ margin-bottom: $default-margin
13
+ }
14
+ }
@@ -72,7 +72,7 @@ const ChoicesInput = ({
72
72
  <Choice
73
73
  key={choice.value}
74
74
  name={name}
75
- id={`${name}-${choice.value}`}
75
+ id={`${id}-${choice.value}`}
76
76
  multiple={multiple}
77
77
  validate={validate}
78
78
  disabled={disabled}
@@ -28,15 +28,7 @@ const Choice = ({
28
28
  validate,
29
29
  disabled,
30
30
  }) => {
31
- const type = multiple ? 'checkbox' : 'radio'
32
-
33
- const [field] = useField({
34
- name,
35
- validate,
36
- type,
37
- value,
38
- })
39
-
31
+ const [field] = useField({ name, validate })
40
32
  return (
41
33
  <div
42
34
  className={[
@@ -51,7 +43,7 @@ const Choice = ({
51
43
  style={style}
52
44
  >
53
45
  <input
54
- type={type}
46
+ type={multiple ? 'checkbox' : 'radio'}
55
47
  id={id}
56
48
  name={name}
57
49
  {...field}
@@ -5,3 +5,4 @@ export { TextareaInput } from './TextareaInput'
5
5
  export { RatingsInput } from './RatingsInput'
6
6
  export { QueryCombobox } from './QueryCombobox'
7
7
  export { QuerySelect } from './QuerySelect'
8
+ export { Checkbox } from './Checkbox'