@edvisor/product-language 0.2.0 → 0.3.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/.eslintrc.json +14 -6
- package/package.json +2 -3
- package/project.json +18 -7
- package/src/README.md +61 -0
- package/src/helpers/index.ts +2 -1
- package/src/helpers/playground.ts +16 -0
- package/src/lib/components/badge/badge.tsx +8 -17
- package/src/lib/components/badge/stories/badge.stories.mdx +44 -0
- package/src/lib/components/badge/stories/components.tsx +49 -0
- package/src/lib/components/card/card.test.tsx +4 -5
- package/src/lib/components/card/card.tsx +2 -2
- package/src/lib/components/card/components/card-section-slot.tsx +2 -2
- package/src/lib/components/card/storybook/card.stories.mdx +1 -1
- package/src/lib/components/card/storybook/components.tsx +6 -23
- package/src/lib/components/checkbox/checkbox.tsx +34 -95
- package/src/lib/components/checkbox/helpers.tsx +100 -0
- package/src/lib/components/checkbox/stories/checkbox.stories.mdx +27 -24
- package/src/lib/components/checkbox/stories/components.tsx +63 -15
- package/src/lib/components/divider/stories/divider.stories.mdx +7 -13
- package/src/lib/components/flag/flag-size-flags.tsx +55 -0
- package/src/lib/components/flag/flag.list.tsx +788 -0
- package/src/lib/components/flag/flag.test.tsx +65 -0
- package/src/lib/components/flag/flag.tsx +97 -0
- package/src/lib/components/flag/index.tsx +1 -0
- package/src/lib/components/flag/stories/components.tsx +403 -0
- package/src/lib/components/flag/stories/flag.stories.mdx +48 -0
- package/src/lib/components/flag/stories/playGround-select.tsx +145 -0
- package/src/lib/components/icon/icon-list.tsx +135 -0
- package/src/lib/components/icon/icon.test.tsx +48 -0
- package/src/lib/components/icon/icon.tsx +181 -0
- package/src/lib/components/icon/index.tsx +1 -0
- package/src/lib/components/icon/stories/components.tsx +282 -0
- package/src/lib/components/icon/stories/icon.stories.mdx +65 -0
- package/src/lib/components/index.ts +5 -0
- package/src/lib/components/input-field/components/labeled-input.tsx +7 -14
- package/src/lib/components/input-field/components/stepper.tsx +4 -3
- package/src/lib/components/input-field/input-field.test.tsx +5 -6
- package/src/lib/components/input-field/input-field.tsx +8 -8
- package/src/lib/components/input-field/storybook/components.tsx +9 -16
- package/src/lib/components/link/storybook/link.stories.mdx +1 -0
- package/src/lib/components/molecules/avatar/avatar-size-flags.tsx +3 -3
- package/src/lib/components/molecules/avatar/avatar.tsx +2 -2
- package/src/lib/components/molecules/avatar/stories/avatar.stories.mdx +18 -21
- package/src/lib/components/molecules/button/button-flags.tsx +120 -15
- package/src/lib/components/molecules/button/button.test.tsx +9 -9
- package/src/lib/components/molecules/button/button.tsx +61 -78
- package/src/lib/components/molecules/button/stories/button.stories.mdx +43 -42
- package/src/lib/components/molecules/button/stories/components.tsx +6 -8
- package/src/lib/components/molecules/input-checkbox/input-checkbox.tsx +23 -24
- package/src/lib/components/molecules/input-checkbox/stories/components.tsx +32 -15
- package/src/lib/components/molecules/input-checkbox/stories/input-checkbox.stories.mdx +6 -8
- package/src/lib/components/organisms/multi-choice-list/multi-choice-list.tsx +7 -8
- package/src/lib/components/organisms/multi-choice-list/stories/components.tsx +3 -5
- package/src/lib/components/organisms/multi-choice-list/stories/multi-choice-list.stories.mdx +4 -4
- package/src/lib/components/spinner/spinner.test.tsx +2 -2
- package/src/lib/components/spinner/spinner.tsx +15 -28
- package/src/lib/components/spinner/stories/components.tsx +33 -2
- package/src/lib/components/spinner/stories/spinner.stories.mdx +3 -10
- package/src/lib/components/tabs/components/index.ts +1 -0
- package/src/lib/components/tabs/components/tab.tsx +62 -0
- package/src/lib/components/tabs/index.tsx +1 -0
- package/src/lib/components/tabs/storybook/components.tsx +282 -0
- package/src/lib/components/tabs/storybook/tabs.stories.mdx +97 -0
- package/src/lib/components/tabs/tabs.test.tsx +86 -0
- package/src/lib/components/tabs/tabs.tsx +101 -0
- package/src/lib/components/tag/components/close-button.tsx +85 -0
- package/src/lib/components/tag/components/index.ts +2 -0
- package/src/lib/components/tag/components/tag-label.tsx +44 -0
- package/src/lib/components/tag/index.tsx +1 -0
- package/src/lib/components/tag/stories/components.tsx +86 -0
- package/src/lib/components/tag/stories/tag.stories.mdx +42 -0
- package/src/lib/components/tag/tag.test.tsx +36 -0
- package/src/lib/components/tag/tag.tsx +33 -0
- package/src/lib/components/thumbnail/thumbnail.tsx +7 -2
- package/src/lib/components/typography/storybook/components.tsx +47 -15
- package/src/lib/components/typography/storybook/typography.stories.mdx +6 -4
- package/src/lib/components/typography/typography.test.tsx +34 -30
- package/src/lib/components/typography/typography.tsx +61 -19
- package/src/lib/foundations/color-system/base-palette/base-palette.ts +0 -1
- package/src/lib/foundations/color-system/color-guidelines/color-guidelines.ts +5 -4
- package/src/lib/foundations/color-system/components/color-sample.tsx +3 -3
- package/src/lib/foundations/typography/fonts.ts +205 -0
- package/src/lib/foundations/typography/text-aspect-flags.ts +11 -4
- package/src/lib/foundations/typography/typography.tsx +38 -33
- package/src/lib/helpers/numbers.ts +14 -0
- package/src/lib/helpers/safe-navigation.ts +10 -0
- package/src/lib/helpers/slots.test.tsx +98 -0
- package/src/lib/helpers/slots.tsx +93 -12
- package/.storybook/preview-head.html +0 -1
- package/src/lib/components/badge/badge.stories.tsx +0 -16
- package/src/lib/components/checkbox/components/components.tsx +0 -59
- package/src/lib/components/checkbox/stories/index.tsx +0 -1
- package/src/lib/components/molecules/input-checkbox/stories/index.tsx +0 -1
- package/src/lib/components/organisms/multi-choice-list/stories/index.tsx +0 -1
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { css } from 'styled-components'
|
|
2
|
+
import { Surface, Borders, Actions, Interactive, Icons } from '@foundations'
|
|
3
|
+
import { Hex, isNil } from '@helpers'
|
|
4
|
+
|
|
5
|
+
interface ICheckedProps {
|
|
6
|
+
checked?: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const WIDTH = 12
|
|
10
|
+
const HEIGHT = 10
|
|
11
|
+
|
|
12
|
+
/** no magic here, just copy/pasted the svg from the mockup
|
|
13
|
+
* I had to tweak the width and height though
|
|
14
|
+
*/
|
|
15
|
+
const svg = `
|
|
16
|
+
<svg xmlns='http://www.w3.org/2000/svg' width='${WIDTH}' height='${HEIGHT}' viewBox='0 0 10 8'>
|
|
17
|
+
<path d='M4.50846 7.37941C4.0689 7.81898 3.35108 7.81898 2.91151 7.37941L0.330581 4.79848C-0.110194 4.35892 -0.110194 3.64109 0.330581 3.20153C0.770146 2.76196 1.48797 2.76196 1.92753 3.20153L3.70999 4.98399L8.07338 0.620598C8.51294 0.181033 9.23076 0.181033 9.67033 0.620598C10.1099 1.06016 10.1099 1.77798 9.67033 2.21755L4.50846 7.37941Z' fill='white'/>
|
|
18
|
+
</svg>
|
|
19
|
+
`
|
|
20
|
+
|
|
21
|
+
function getCheckMark () {
|
|
22
|
+
return css`
|
|
23
|
+
::before {
|
|
24
|
+
position: absolute;
|
|
25
|
+
content: url("data:image/svg+xml,${svg}");
|
|
26
|
+
top: 3px;
|
|
27
|
+
left: 3px;
|
|
28
|
+
}
|
|
29
|
+
`
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** the reason I have this isNil to test
|
|
33
|
+
* whether `checked` was passes is this:
|
|
34
|
+
*
|
|
35
|
+
* if the user passed "checked" then
|
|
36
|
+
* they expect the checked styles to be
|
|
37
|
+
* seen if and only if checked is true.
|
|
38
|
+
* In that case I don't add the :checked
|
|
39
|
+
* selector because the user doesn't want
|
|
40
|
+
* the styles to depend on the browser's
|
|
41
|
+
* idea of the state of the button.
|
|
42
|
+
*/
|
|
43
|
+
function getCheckedStyles (color: Hex) {
|
|
44
|
+
return css<{ checked?: boolean }>`
|
|
45
|
+
${({ checked }) => isNil(checked)
|
|
46
|
+
? css`
|
|
47
|
+
:checked {
|
|
48
|
+
background: ${color};
|
|
49
|
+
border: 2px solid ${color};
|
|
50
|
+
${getCheckMark()}
|
|
51
|
+
}
|
|
52
|
+
`
|
|
53
|
+
: checked
|
|
54
|
+
? css`
|
|
55
|
+
background: ${color};
|
|
56
|
+
border: 2px solid ${color};
|
|
57
|
+
${getCheckMark()}
|
|
58
|
+
`
|
|
59
|
+
: ''
|
|
60
|
+
}
|
|
61
|
+
`
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const getHoverStyles = () => css`
|
|
65
|
+
background: ${Surface.Default.Hover};
|
|
66
|
+
|
|
67
|
+
${getCheckedStyles(Interactive.Default.Hover)}
|
|
68
|
+
`
|
|
69
|
+
|
|
70
|
+
export const getDisabledStyles = () => css`
|
|
71
|
+
pointer-events: none;
|
|
72
|
+
background: ${(props: ICheckedProps) =>
|
|
73
|
+
props.checked === true
|
|
74
|
+
? `${Borders.Default.Default}`
|
|
75
|
+
: `${Surface.Default.Subdued}`};
|
|
76
|
+
border: 2px solid ${Borders.Default.Default};
|
|
77
|
+
|
|
78
|
+
${getCheckedStyles(Icons.Disabled)}
|
|
79
|
+
`
|
|
80
|
+
|
|
81
|
+
export const getDefaultStyles = () => css`
|
|
82
|
+
background: ${Surface.Default.Default};
|
|
83
|
+
border: 2px solid ${Interactive.Default.Disabled};
|
|
84
|
+
|
|
85
|
+
${getCheckedStyles(Interactive.Default.Default)}
|
|
86
|
+
|
|
87
|
+
:hover {
|
|
88
|
+
${getHoverStyles}
|
|
89
|
+
}
|
|
90
|
+
`
|
|
91
|
+
|
|
92
|
+
export const getInvalidStyles = () => css`
|
|
93
|
+
background: ${(props: ICheckedProps) =>
|
|
94
|
+
props.checked === true
|
|
95
|
+
? `${Actions.Critical.Default}`
|
|
96
|
+
: `${Surface.Critical.Subdued}`};
|
|
97
|
+
border: 2px solid ${Borders.Critical.Default};
|
|
98
|
+
|
|
99
|
+
${getCheckedStyles(Icons.Critical)}
|
|
100
|
+
`
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Canvas, Meta, Story } from '@storybook/addon-docs';
|
|
2
|
-
import { Checkbox } from '../
|
|
3
|
-
import {
|
|
2
|
+
import { Checkbox } from '../checkbox'
|
|
3
|
+
import { IntegratedExample, CheckboxExample, LimitationsExample } from './components'
|
|
4
4
|
|
|
5
5
|
<Meta
|
|
6
6
|
title="Components/Checkbox"
|
|
@@ -9,46 +9,49 @@ import { PlainHTMLFormExample } from './index'
|
|
|
9
9
|
|
|
10
10
|
# Checkbox
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
Checkboxes are most commonly used to give users a way to make a range of selections (zero, one, or multiple). They may also be used as a way to have users indicate they agree to specific terms and services.
|
|
13
13
|
|
|
14
14
|
For more details, check out the component page on [Figma](https://www.figma.com/file/ue1CurHfZ426o2T2l8Dk64/Edvisor-Product-Language?node-id=1008%3A1257)
|
|
15
15
|
|
|
16
16
|
## How to use
|
|
17
17
|
|
|
18
|
-
```
|
|
19
|
-
// Import the component
|
|
18
|
+
```tsx
|
|
20
19
|
import { Checkbox } from './index'
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
// Render the component sending the required parameters
|
|
24
21
|
<Checkbox />
|
|
25
22
|
```
|
|
26
23
|
|
|
27
|
-
|
|
24
|
+
### Typical Usage
|
|
28
25
|
|
|
29
|
-
|
|
30
|
-
<Checkbox onChange={(e) => console.log('at stories', e)} />
|
|
31
|
-
<Checkbox disabled />
|
|
32
|
-
<Checkbox error />
|
|
33
|
-
<Checkbox checked />
|
|
34
|
-
<Checkbox error checked />
|
|
35
|
-
</Canvas>
|
|
26
|
+
Checkbox is "drop-in" compatible with an html input checkbox.
|
|
36
27
|
|
|
28
|
+
<IntegratedExample />
|
|
37
29
|
|
|
38
|
-
|
|
30
|
+
### Modifiers
|
|
39
31
|
|
|
40
|
-
|
|
41
|
-
| ---- | ----- | ------ | ------- |
|
|
42
|
-
| `checked` | `boolean` | `Set checkbox as filled` | `N` |
|
|
43
|
-
| `disabled` | `boolean` | `Set checkbox as a disabled way (can't click or interact with that)` | `N` |
|
|
44
|
-
| `error` | `boolean` | `Useful to work inside a form or show some feedback from user action` | `N` |
|
|
45
|
-
| `onChange` | `event` | `You can listen the changes from the component` | `N` |
|
|
32
|
+
Control the appearance of the checkbox with its modifiers.
|
|
46
33
|
|
|
34
|
+
<CheckboxExample />
|
|
35
|
+
|
|
36
|
+
## API
|
|
47
37
|
|
|
48
|
-
|
|
38
|
+
Extends `HTMLAttributes<HTMLInputElement>`
|
|
49
39
|
|
|
50
|
-
|
|
40
|
+
| Name | Type | Description |
|
|
41
|
+
| ----------- | --------- | ------------------------------------------------------------------- |
|
|
42
|
+
| `checked?` | `boolean` | Set checkbox as filled |
|
|
43
|
+
| `disabled?` | `boolean` | Set checkbox as a disabled way (can't click or interact with that) |
|
|
44
|
+
| `error?` | `boolean` | Useful to work inside a form or show some feedback from user action |
|
|
45
|
+
| `onChange?` | `event` | You can listen the changes from the component |
|
|
51
46
|
|
|
52
47
|
## Changelog
|
|
48
|
+
|
|
49
|
+
### [0.1.0]
|
|
50
|
+
- replace the checkbox implementation with an input type=checkbox styled to look like what we need
|
|
51
|
+
|
|
52
|
+
### [0.0.1]
|
|
53
|
+
- update checkbox to behave more like html input with type='checkbox'
|
|
54
|
+
|
|
55
|
+
### [0.0.0]
|
|
53
56
|
- Offer the "indeterminate" style
|
|
54
57
|
- Get feedback from the component usage (we can migrate to just rendering with css pseudo elements if necessary)
|
|
@@ -1,35 +1,83 @@
|
|
|
1
|
+
import { Margin, } from '@foundations'
|
|
2
|
+
import { If } from '@helpers'
|
|
3
|
+
import { Button } from 'components/molecules/button'
|
|
4
|
+
import { Caption, Label } from 'components/typography'
|
|
1
5
|
import { Playground } from 'storybook-addon-jarle-monaco'
|
|
2
|
-
import
|
|
6
|
+
import styled from 'styled-components'
|
|
7
|
+
import { Checkbox as Base } from '../checkbox'
|
|
3
8
|
|
|
4
|
-
|
|
9
|
+
const Checkbox = styled(Base)`
|
|
10
|
+
display: inline-block;
|
|
11
|
+
`
|
|
12
|
+
|
|
13
|
+
export const CheckboxExample = () => (
|
|
14
|
+
<Playground
|
|
15
|
+
code={`
|
|
16
|
+
<>
|
|
17
|
+
<Checkbox />
|
|
18
|
+
<Checkbox checked readOnly />
|
|
19
|
+
<Checkbox disabled />
|
|
20
|
+
<Checkbox checked disabled readOnly />
|
|
21
|
+
<Checkbox error />
|
|
22
|
+
<Checkbox checked error readOnly />
|
|
23
|
+
</>
|
|
24
|
+
`}
|
|
25
|
+
providerProps={{
|
|
26
|
+
renderAsComponent: true,
|
|
27
|
+
scope: {
|
|
28
|
+
Checkbox,
|
|
29
|
+
},
|
|
30
|
+
}}
|
|
31
|
+
/>
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
const Fields = styled.div`
|
|
35
|
+
margin-bottom: ${Margin.s};
|
|
36
|
+
`
|
|
37
|
+
|
|
38
|
+
export const IntegratedExample = () => (
|
|
5
39
|
<Playground
|
|
6
40
|
code={`
|
|
7
41
|
/* Edit this code sample! */
|
|
8
42
|
const [withError, setWithError] = useState(false);
|
|
43
|
+
const [accepted, setAccepted] = useState(false);
|
|
9
44
|
|
|
10
45
|
<form onSubmit={(e) => {
|
|
11
46
|
e.preventDefault()
|
|
12
|
-
console.log('form submitted')
|
|
13
47
|
}}
|
|
14
48
|
>
|
|
15
|
-
<
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
49
|
+
<Fields>
|
|
50
|
+
{/* try replacing Checkbox with input */}
|
|
51
|
+
<Checkbox
|
|
52
|
+
id="accept_terms"
|
|
53
|
+
type="checkbox"
|
|
54
|
+
checked={accepted}
|
|
55
|
+
onInvalid={(e) => {
|
|
56
|
+
setWithError(true)
|
|
57
|
+
}}
|
|
58
|
+
error={withError}
|
|
59
|
+
onChange={(e) => {
|
|
60
|
+
setAccepted(!accepted)
|
|
61
|
+
setWithError(false)
|
|
62
|
+
}}
|
|
63
|
+
required
|
|
64
|
+
/>
|
|
65
|
+
<label htmlFor="accept_terms"><Label as='span'>I accept these terms.</Label></label>
|
|
66
|
+
<If is={accepted}><Caption subdued>You have accepted the terms.</Caption></If>
|
|
67
|
+
</Fields>
|
|
68
|
+
<Button type='button' onClick={() => setAccepted(false)}>Clear</Button>
|
|
69
|
+
<Button primary type="submit">Submit</Button>
|
|
27
70
|
</form>
|
|
28
71
|
`}
|
|
29
72
|
providerProps={{
|
|
30
73
|
renderAsComponent: true,
|
|
31
74
|
scope: {
|
|
32
75
|
Checkbox,
|
|
76
|
+
Caption,
|
|
77
|
+
Button,
|
|
78
|
+
If,
|
|
79
|
+
Label,
|
|
80
|
+
Fields,
|
|
33
81
|
},
|
|
34
82
|
}}
|
|
35
83
|
/>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Canvas, Meta
|
|
1
|
+
import { Canvas, Meta } from '@storybook/addon-docs';
|
|
2
2
|
import { Divider } from '../index'
|
|
3
3
|
import { WrapperStories, AvatarsWithText, AvatarsWithImage, WrapperStoriesWithLabel } from './components'
|
|
4
4
|
|
|
@@ -29,22 +29,16 @@ import { Divider } from './index'
|
|
|
29
29
|
## Examples
|
|
30
30
|
|
|
31
31
|
Default Divider
|
|
32
|
-
|
|
33
32
|
<Canvas>
|
|
34
|
-
<
|
|
35
|
-
<
|
|
36
|
-
|
|
37
|
-
</WrapperStories>
|
|
38
|
-
</Story>
|
|
33
|
+
<WrapperStories>
|
|
34
|
+
<Divider default/>
|
|
35
|
+
</WrapperStories>
|
|
39
36
|
</Canvas>
|
|
40
37
|
|
|
41
38
|
Subdued Divider
|
|
42
|
-
|
|
43
39
|
<Canvas>
|
|
44
|
-
<
|
|
45
|
-
<
|
|
46
|
-
|
|
47
|
-
</WrapperStories>
|
|
48
|
-
</Story>
|
|
40
|
+
<WrapperStories>
|
|
41
|
+
<Divider subdued/>
|
|
42
|
+
</WrapperStories>
|
|
49
43
|
</Canvas>
|
|
50
44
|
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { bitwiseOr, MappedEnum, RequireOnlyOne, PropsWithChildren } from '@helpers'
|
|
2
|
+
|
|
3
|
+
export const enum FlagSize {
|
|
4
|
+
small = 1,
|
|
5
|
+
medium = 2,
|
|
6
|
+
large = 4,
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
type FlagSizes<T> = MappedEnum<typeof FlagSize, T>
|
|
10
|
+
|
|
11
|
+
function toFlag(n: number): FlagSize {
|
|
12
|
+
switch (n) {
|
|
13
|
+
case FlagSize.small:
|
|
14
|
+
return FlagSize.small
|
|
15
|
+
case FlagSize.medium:
|
|
16
|
+
return FlagSize.medium
|
|
17
|
+
case FlagSize.large:
|
|
18
|
+
return FlagSize.large
|
|
19
|
+
default:
|
|
20
|
+
return FlagSize.medium
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const FlagWidthValues = {
|
|
25
|
+
[FlagSize.small]: '20',
|
|
26
|
+
[FlagSize.medium]: '20',
|
|
27
|
+
[FlagSize.large]: '32',
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const FlagHeightValues = {
|
|
31
|
+
[FlagSize.small]: '20',
|
|
32
|
+
[FlagSize.medium]: '20',
|
|
33
|
+
[FlagSize.large]: '24',
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type FlagProps = Partial<RequireOnlyOne<FlagSizes<boolean>>> &
|
|
37
|
+
PropsWithChildren
|
|
38
|
+
|
|
39
|
+
export function getHeigthBySize(props: FlagProps): string {
|
|
40
|
+
return FlagHeightValues[
|
|
41
|
+
getFlagSize(props)
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function getWidthBySize(props: FlagProps): string {
|
|
46
|
+
return FlagWidthValues[
|
|
47
|
+
getFlagSize(props)
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function getFlagSize(props: FlagProps) {
|
|
52
|
+
return toFlag(
|
|
53
|
+
bitwiseOr([props.small, props.medium, props.large])
|
|
54
|
+
)
|
|
55
|
+
}
|