@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
|
@@ -1,95 +1,100 @@
|
|
|
1
1
|
import { css } from 'styled-components'
|
|
2
|
-
import { getTextAspect,
|
|
2
|
+
import { getTextAspect, ITransientTextAspectProps } from './text-aspect-flags'
|
|
3
3
|
import { FontWeight, FontSize, LineHeight } from './constants'
|
|
4
4
|
import { is } from '@helpers'
|
|
5
|
+
import { InterFontFace } from './fonts'
|
|
5
6
|
|
|
6
|
-
export type
|
|
7
|
+
export type ILabelProps = ITransientTextAspectProps & {
|
|
8
|
+
default?: boolean,
|
|
9
|
+
subtle?: boolean,
|
|
10
|
+
strong?: boolean,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type IBodyProps = ITransientTextAspectProps & {
|
|
14
|
+
default?: boolean,
|
|
15
|
+
strong?: boolean,
|
|
16
|
+
}
|
|
7
17
|
|
|
8
18
|
const LightText = css`
|
|
9
19
|
color: ${getTextAspect({ light: true })};
|
|
10
20
|
`
|
|
11
21
|
|
|
12
|
-
const Base = css<
|
|
22
|
+
const Base = css<ITransientTextAspectProps>`
|
|
13
23
|
color: ${(props) => getTextAspect(props)};
|
|
24
|
+
${InterFontFace}
|
|
14
25
|
font-family: 'Inter';
|
|
15
26
|
`
|
|
16
27
|
|
|
17
|
-
const Display = css<
|
|
28
|
+
const Display = css<ITransientTextAspectProps>`
|
|
18
29
|
${Base}
|
|
19
30
|
font-weight: ${FontWeight.Regular};
|
|
20
31
|
font-size: ${FontSize.g};
|
|
21
32
|
line-height: ${LineHeight.f};
|
|
22
33
|
`
|
|
23
34
|
|
|
24
|
-
const Heading1 = css<
|
|
35
|
+
const Heading1 = css<ITransientTextAspectProps>`
|
|
25
36
|
${Base}
|
|
26
37
|
font-weight: ${FontWeight.SemiBold};
|
|
27
38
|
font-size: ${FontSize.f};
|
|
28
39
|
line-height: ${LineHeight.e};
|
|
29
40
|
`
|
|
30
41
|
|
|
31
|
-
const Heading2 = css<
|
|
42
|
+
const Heading2 = css<ITransientTextAspectProps>`
|
|
32
43
|
${Heading1}
|
|
33
44
|
font-size: ${FontSize.e};
|
|
34
45
|
line-height: ${LineHeight.d};
|
|
35
46
|
`
|
|
36
47
|
|
|
37
|
-
const Heading3 = css<
|
|
48
|
+
const Heading3 = css<ITransientTextAspectProps>`
|
|
38
49
|
${Heading1}
|
|
39
50
|
font-size: ${FontSize.c};
|
|
40
51
|
line-height: ${LineHeight.c};
|
|
41
52
|
`
|
|
42
53
|
|
|
43
|
-
const Heading4 = css<
|
|
54
|
+
const Heading4 = css<ITransientTextAspectProps>`
|
|
44
55
|
${Heading1}
|
|
45
56
|
font-size: ${FontSize.b};
|
|
46
57
|
line-height: ${LineHeight.b};
|
|
47
58
|
`
|
|
48
59
|
|
|
49
|
-
const
|
|
60
|
+
const Body = css<IBodyProps>`
|
|
50
61
|
${Base}
|
|
51
|
-
font-weight: ${({
|
|
52
|
-
font-size: ${FontSize.d};
|
|
53
|
-
line-height: ${LineHeight.d};
|
|
54
|
-
`
|
|
55
|
-
|
|
56
|
-
const Body = css<ITextProps>`
|
|
57
|
-
${BodyLarge}
|
|
58
|
-
font-weight: ${({ emphasis }) => is(emphasis) ? FontWeight.Medium : FontWeight.Regular};
|
|
62
|
+
font-weight: ${({ strong }) => is(strong) ? FontWeight.Medium : FontWeight.Regular};
|
|
59
63
|
font-size: ${FontSize.b};
|
|
60
64
|
line-height: ${LineHeight.b};
|
|
61
65
|
`
|
|
62
66
|
|
|
63
|
-
const
|
|
64
|
-
${
|
|
65
|
-
font-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const Label1 = css<ITextProps>`
|
|
70
|
-
${BodyLarge}
|
|
71
|
-
font-weight: ${({ emphasis }) => is(emphasis) ? FontWeight.Medium : FontWeight.Regular};
|
|
72
|
-
font-size: ${FontSize.b};
|
|
73
|
-
line-height: ${LineHeight.b};
|
|
67
|
+
const BodyLarge = css<IBodyProps>`
|
|
68
|
+
${Base}
|
|
69
|
+
font-weight: ${({ strong }) => is(strong) ? FontWeight.SemiBold : FontWeight.Regular};
|
|
70
|
+
font-size: ${FontSize.d};
|
|
71
|
+
line-height: ${LineHeight.d};
|
|
74
72
|
`
|
|
75
73
|
|
|
76
|
-
const
|
|
77
|
-
${
|
|
74
|
+
const Caption = css<ITransientTextAspectProps>`
|
|
75
|
+
${Base}
|
|
76
|
+
font-weight: ${FontWeight.Regular};
|
|
78
77
|
font-size: ${FontSize.a};
|
|
79
78
|
line-height: ${LineHeight.a};
|
|
80
79
|
`
|
|
81
80
|
|
|
81
|
+
const Label = css<ILabelProps>`
|
|
82
|
+
${Base}
|
|
83
|
+
font-weight: ${({ strong }) => is(strong) ? FontWeight.Medium : FontWeight.Regular};
|
|
84
|
+
font-size: ${({ subtle }) => is(subtle) ? FontSize.a : FontSize.b};
|
|
85
|
+
line-height: ${({ subtle }) => is(subtle) ? LineHeight.a : LineHeight.b};
|
|
86
|
+
`
|
|
87
|
+
|
|
82
88
|
export const Typography = {
|
|
83
89
|
Display,
|
|
84
90
|
Heading1,
|
|
85
91
|
Heading2,
|
|
86
92
|
Heading3,
|
|
87
93
|
Heading4,
|
|
88
|
-
BodyLarge,
|
|
89
94
|
Body,
|
|
95
|
+
BodyLarge,
|
|
90
96
|
Caption,
|
|
91
|
-
|
|
92
|
-
Label2,
|
|
97
|
+
Label,
|
|
93
98
|
}
|
|
94
99
|
|
|
95
100
|
export const _Typography = {
|
|
@@ -51,3 +51,17 @@ export function concatHex(a: Hex, b: Hex): Hex {
|
|
|
51
51
|
export function bitwiseOr(flags: unknown[]): number {
|
|
52
52
|
return flags.reduce((mask: number, flag, i) => mask | (Number(flag) << i), 0)
|
|
53
53
|
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
/** given a number, it returns the number formed by the rightmost set bit as 1 and the 0s that comes after it
|
|
57
|
+
*
|
|
58
|
+
* ```ts
|
|
59
|
+
* getRightmostSetBitNumber(12) => 4 // 12(1100) => 4(100)
|
|
60
|
+
* getRightmostSetBitNumber(40) => 8 // 40(101000) => 8(1000)
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* */
|
|
64
|
+
|
|
65
|
+
export function getRightmostSetBitNumber(n: number) {
|
|
66
|
+
return n & -n
|
|
67
|
+
}
|
|
@@ -32,3 +32,13 @@ export function is (pred?: boolean): boolean {
|
|
|
32
32
|
export function safeArray<T>(arr: T[] | undefined | null): T[] {
|
|
33
33
|
return isDefined(arr) ? arr : []
|
|
34
34
|
}
|
|
35
|
+
|
|
36
|
+
export function safeCallback <T>(f?: (e: T) => void, e?: T) {
|
|
37
|
+
if (isDefined(f)) {
|
|
38
|
+
if (isDefined(e)) {
|
|
39
|
+
f(e)
|
|
40
|
+
} else {
|
|
41
|
+
(f as () => void)()
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import styled from 'styled-components'
|
|
2
|
+
import { FC } from './generic-types'
|
|
3
|
+
import { isReactElementOfType, Slot } from './slots'
|
|
4
|
+
|
|
5
|
+
describe('isReactElementOfType', () => {
|
|
6
|
+
describe('class component', () => {
|
|
7
|
+
class Bob extends Slot {}
|
|
8
|
+
|
|
9
|
+
describe('both component and element are unstyled', () => {
|
|
10
|
+
it('knows when they are different', () => {
|
|
11
|
+
expect(isReactElementOfType(Bob)(<div />)).toBe(false)
|
|
12
|
+
})
|
|
13
|
+
it('knows when they are the same', () => {
|
|
14
|
+
expect(isReactElementOfType(Bob)(<Bob />)).toBe(true)
|
|
15
|
+
})
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
describe('component type is styled', () => {
|
|
19
|
+
const StyledBob = styled(Bob)``
|
|
20
|
+
|
|
21
|
+
it('knows when they are different', () => {
|
|
22
|
+
expect(isReactElementOfType(StyledBob)(<div />)).toBe(false)
|
|
23
|
+
})
|
|
24
|
+
it('knows when they are the same', () => {
|
|
25
|
+
expect(isReactElementOfType(StyledBob)(<Bob />)).toBe(true)
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
describe('element is styled', () => {
|
|
30
|
+
const StyledBob = styled(Bob)``
|
|
31
|
+
|
|
32
|
+
it('knows when they are different', () => {
|
|
33
|
+
expect(isReactElementOfType(Bob)(<div />)).toBe(false)
|
|
34
|
+
})
|
|
35
|
+
it('knows when they are the same', () => {
|
|
36
|
+
expect(isReactElementOfType(Bob)(<StyledBob />)).toBe(true)
|
|
37
|
+
})
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
describe('both component and element are styled', () => {
|
|
41
|
+
const StyledBob = styled(Bob)``
|
|
42
|
+
|
|
43
|
+
it('knows when they are different', () => {
|
|
44
|
+
expect(isReactElementOfType(StyledBob)(<div />)).toBe(false)
|
|
45
|
+
})
|
|
46
|
+
it('knows when they are the same', () => {
|
|
47
|
+
expect(isReactElementOfType(StyledBob)(<StyledBob />)).toBe(true)
|
|
48
|
+
})
|
|
49
|
+
})
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
describe('function component', () => {
|
|
53
|
+
const Bob: FC = () => <div />
|
|
54
|
+
|
|
55
|
+
describe('both component and element are unstyled', () => {
|
|
56
|
+
it('knows when they are different', () => {
|
|
57
|
+
expect(isReactElementOfType(Bob)(<div />)).toBe(false)
|
|
58
|
+
})
|
|
59
|
+
it('knows when they are the same', () => {
|
|
60
|
+
expect(isReactElementOfType(Bob)(<Bob />)).toBe(true)
|
|
61
|
+
})
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
describe('component type is styled', () => {
|
|
65
|
+
const StyledBob = styled(Bob)``
|
|
66
|
+
|
|
67
|
+
it('knows when they are different', () => {
|
|
68
|
+
expect(isReactElementOfType(StyledBob)(<div />)).toBe(false)
|
|
69
|
+
})
|
|
70
|
+
it('knows when they are the same', () => {
|
|
71
|
+
expect(isReactElementOfType(StyledBob)(<Bob />)).toBe(true)
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
describe('element is styled', () => {
|
|
76
|
+
const StyledBob = styled(Bob)``
|
|
77
|
+
|
|
78
|
+
it('knows when they are different', () => {
|
|
79
|
+
expect(isReactElementOfType(Bob)(<div />)).toBe(false)
|
|
80
|
+
})
|
|
81
|
+
it('knows when they are the same', () => {
|
|
82
|
+
expect(isReactElementOfType(Bob)(<StyledBob />)).toBe(true)
|
|
83
|
+
})
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
describe('both component and element are styled', () => {
|
|
87
|
+
const StyledBob = styled(Bob)``
|
|
88
|
+
|
|
89
|
+
it('knows when they are different', () => {
|
|
90
|
+
expect(isReactElementOfType(StyledBob)(<div />)).toBe(false)
|
|
91
|
+
})
|
|
92
|
+
it('knows when they are the same', () => {
|
|
93
|
+
expect(isReactElementOfType(StyledBob)(<StyledBob />)).toBe(true)
|
|
94
|
+
})
|
|
95
|
+
})
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
})
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { Children, PureComponent, ReactElement, ReactNode } from 'react'
|
|
2
|
-
import {
|
|
1
|
+
import { Children, CSSProperties, PureComponent, ReactElement, ReactNode } from 'react'
|
|
2
|
+
import { StyledComponent } from 'styled-components'
|
|
3
|
+
import { FC, PropsWithChildren } from './generic-types'
|
|
4
|
+
import { Nothing } from './nothing'
|
|
3
5
|
import { isDefined, isNil } from './safe-navigation'
|
|
4
6
|
|
|
5
7
|
/**
|
|
@@ -22,17 +24,64 @@ function isReactElement (obj?: any): obj is ReactElement {
|
|
|
22
24
|
return isDefined(obj) && obj.hasOwnProperty('type')
|
|
23
25
|
}
|
|
24
26
|
|
|
27
|
+
export const isReactElementOfType =
|
|
28
|
+
<P extends PropsWithChildren>(
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/no-explicit-any
|
|
30
|
+
component: (StyledComponent<FC<P>, any> | FC<P> | typeof Slot) & {
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/no-explicit-any
|
|
32
|
+
target?: any
|
|
33
|
+
}
|
|
34
|
+
) =>
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/no-explicit-any
|
|
36
|
+
(element?: any): element is ReactElement<P> => {
|
|
37
|
+
/**
|
|
38
|
+
* I'm going to leave this as a big if/else instead of a compound expression to make
|
|
39
|
+
* it clear exactly what we are checking.
|
|
40
|
+
*/
|
|
41
|
+
if (element?.type === component) {
|
|
42
|
+
// component is a function or a class, and element is an element of that type
|
|
43
|
+
return true
|
|
44
|
+
} else if (element?.type?.target === component) {
|
|
45
|
+
// element is a styled element of the given component
|
|
46
|
+
// so we have to look at what it is styling (its target)
|
|
47
|
+
return true
|
|
48
|
+
} else if (isDefined(component?.target) && element?.type === component?.target) {
|
|
49
|
+
// component is the type of a styled component
|
|
50
|
+
// and element is an element of the original unstyled component,
|
|
51
|
+
// so we have to look at the target of the component itself (what it styled)
|
|
52
|
+
return true
|
|
53
|
+
} else if (
|
|
54
|
+
isDefined(component?.target) &&
|
|
55
|
+
element?.type?.target === component?.target
|
|
56
|
+
) {
|
|
57
|
+
// element and component are both styled, possibly _differently_
|
|
58
|
+
// but their underlying component type is the same
|
|
59
|
+
return true
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return false
|
|
63
|
+
}
|
|
64
|
+
|
|
25
65
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
|
-
const isSlotOfType = <T extends typeof Slot>(type: T) => (obj?: any): obj is T => {
|
|
27
|
-
return
|
|
66
|
+
export const isSlotOfType = <T extends typeof Slot>(type: T | FC) => (obj?: any): obj is T => {
|
|
67
|
+
return (
|
|
68
|
+
(isDefined(obj) &&
|
|
69
|
+
isReactElement(obj) &&
|
|
70
|
+
isDefined(obj.type) &&
|
|
71
|
+
(Object.getPrototypeOf(obj.type) === type || obj.type === type)) ||
|
|
72
|
+
(isDefined(obj.type) &&
|
|
73
|
+
isDefined(obj.type.target) &&
|
|
74
|
+
(Object.getPrototypeOf(obj.type.target) === type ||
|
|
75
|
+
obj.type.target === type))
|
|
76
|
+
)
|
|
28
77
|
}
|
|
29
78
|
|
|
30
|
-
const findSlotByType = <T extends typeof Slot>(type: T, children?: ReactNode):
|
|
31
|
-
return Children.toArray(children).find(isSlotOfType(type))
|
|
79
|
+
const findSlotByType = <T extends typeof Slot>(type: T, children?: ReactNode): ReactElement => {
|
|
80
|
+
return Children.toArray(children).find(isSlotOfType(type)) as ReactElement
|
|
32
81
|
}
|
|
33
82
|
|
|
34
|
-
const filterSlotByType = <T extends typeof Slot>(type: T, children?: ReactNode):
|
|
35
|
-
return Children.toArray(children).filter(isSlotOfType(type))
|
|
83
|
+
const filterSlotByType = <T extends typeof Slot>(type: T, children?: ReactNode): ReactElement[] => {
|
|
84
|
+
return Children.toArray(children).filter(isSlotOfType(type)) as ReactElement[]
|
|
36
85
|
}
|
|
37
86
|
|
|
38
87
|
export class Slot<T = unknown> extends PureComponent<PropsWithChildren<T>> {
|
|
@@ -41,11 +90,18 @@ export class Slot<T = unknown> extends PureComponent<PropsWithChildren<T>> {
|
|
|
41
90
|
}
|
|
42
91
|
}
|
|
43
92
|
|
|
44
|
-
export
|
|
93
|
+
export class StylableSlot extends Slot {
|
|
94
|
+
override render () {
|
|
95
|
+
return <div {...this.props}>{this.props.children}</div>
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** gets children that are _not_ slots */
|
|
100
|
+
export function getOtherChildren(children?: ReactNode): ReactNode[] {
|
|
45
101
|
return Children.toArray(children).filter((child) => !isSlotOfType(Slot)(child))
|
|
46
102
|
}
|
|
47
103
|
|
|
48
|
-
export function getSlots<T extends typeof Slot>(slot: T, children?: ReactNode):
|
|
104
|
+
export function getSlots<T extends typeof Slot>(slot: T, children?: ReactNode): ReactElement[] {
|
|
49
105
|
const result = filterSlotByType(slot, children)
|
|
50
106
|
|
|
51
107
|
if (isNil(result)) {
|
|
@@ -61,11 +117,11 @@ function hasProps (obj: any): obj is { props: { children: ReactNode }} {
|
|
|
61
117
|
return isDefined(obj) && obj.hasOwnProperty('props')
|
|
62
118
|
}
|
|
63
119
|
|
|
64
|
-
export function getSlot<T extends typeof Slot>(slot: T, children?: ReactNode):
|
|
120
|
+
export function getSlot<T extends typeof Slot>(slot: T, children?: ReactNode): ReactElement {
|
|
65
121
|
const result = findSlotByType(slot, children)
|
|
66
122
|
|
|
67
123
|
if (isNil(result)) {
|
|
68
|
-
return
|
|
124
|
+
return <Nothing />
|
|
69
125
|
}
|
|
70
126
|
|
|
71
127
|
if (hasProps(result)) {
|
|
@@ -73,4 +129,29 @@ export function getSlot<T extends typeof Slot>(slot: T, children?: ReactNode): R
|
|
|
73
129
|
}
|
|
74
130
|
|
|
75
131
|
return result
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** given a ReactElement, like a child, apply the given props to it */
|
|
135
|
+
export function applyProps<T>(element: ReactElement<T>, props: Partial<T>): ReactElement {
|
|
136
|
+
return {
|
|
137
|
+
...element,
|
|
138
|
+
props: {
|
|
139
|
+
...element.props,
|
|
140
|
+
...props,
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** given a ReactElement, like a child, apply the given styles to it, merging with the existing styles */
|
|
146
|
+
export function applyStyle(element: ReactElement, style: CSSProperties): ReactElement {
|
|
147
|
+
return {
|
|
148
|
+
...element,
|
|
149
|
+
props: {
|
|
150
|
+
...element.props,
|
|
151
|
+
style: {
|
|
152
|
+
...element.props.style,
|
|
153
|
+
...style,
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
}
|
|
76
157
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:ital,wght@0,300;0,400;0,500;1,300&display=swap%7CLato:400,700" media="all"></link>
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { StoryComponent, talesOf } from '@stories'
|
|
2
|
-
import { Badge } from './badge'
|
|
3
|
-
|
|
4
|
-
const Story: StoryComponent = () => {
|
|
5
|
-
return (
|
|
6
|
-
<>
|
|
7
|
-
<Badge neutral>Neutral</Badge>
|
|
8
|
-
<Badge info>Informational</Badge>
|
|
9
|
-
<Badge warning>Warning</Badge>
|
|
10
|
-
<Badge success>Success</Badge>
|
|
11
|
-
<Badge critical>Critical</Badge>
|
|
12
|
-
</>
|
|
13
|
-
)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
talesOf(__filename, module, Story)
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import styled, { css } from 'styled-components'
|
|
2
|
-
import { Padding, Surface, Borders, Actions } from '@foundations'
|
|
3
|
-
|
|
4
|
-
interface ICheckedProps {
|
|
5
|
-
checked: boolean;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const getHoverStyles = () => css`
|
|
9
|
-
background: ${Surface.Default.Hover};
|
|
10
|
-
`
|
|
11
|
-
|
|
12
|
-
export const getDisabledStyles = () => css`
|
|
13
|
-
pointer-events: none;
|
|
14
|
-
background: ${(props: ICheckedProps) => (props.checked === true ? `${Borders.Default.Default}`: `${Surface.Default.Subdued}` )};
|
|
15
|
-
border-color: ${Borders.Default.Default};
|
|
16
|
-
`
|
|
17
|
-
|
|
18
|
-
export const getInvalidStyles = () => css`
|
|
19
|
-
background: ${(props: ICheckedProps) => (props.checked === true ? `${Actions.Critical.Default}`: `${Surface.Critical.Subdued}`)};
|
|
20
|
-
border: 2px solid ${Borders.Critical.Default};
|
|
21
|
-
`
|
|
22
|
-
|
|
23
|
-
export const HiddenCheckbox = styled.input`
|
|
24
|
-
border: 0;
|
|
25
|
-
clip: rect(0 0 0 0);
|
|
26
|
-
clippath: inset(50%);
|
|
27
|
-
height: 1px;
|
|
28
|
-
margin: -1px;
|
|
29
|
-
overflow: hidden;
|
|
30
|
-
padding: ${Padding.none};
|
|
31
|
-
position: absolute;
|
|
32
|
-
white-space: nowrap;
|
|
33
|
-
width: 1px;
|
|
34
|
-
`
|
|
35
|
-
|
|
36
|
-
export const Icon = styled.svg`
|
|
37
|
-
width: 100%;
|
|
38
|
-
height: 50%;
|
|
39
|
-
`
|
|
40
|
-
|
|
41
|
-
export const Wrapper = styled.div`
|
|
42
|
-
width: 18px;
|
|
43
|
-
height: 100%;
|
|
44
|
-
`
|
|
45
|
-
|
|
46
|
-
export const getTabIndexValue = (
|
|
47
|
-
disabled: boolean
|
|
48
|
-
): number => {
|
|
49
|
-
return disabled ? -1 : 0
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export const getCheckedIcon = () => (
|
|
53
|
-
<Icon width="10" height="8" viewBox="0 0 10 8">
|
|
54
|
-
<path
|
|
55
|
-
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"
|
|
56
|
-
fill="white"
|
|
57
|
-
/>
|
|
58
|
-
</Icon>
|
|
59
|
-
)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './components'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './components'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './components'
|