@edvisor/product-language 0.1.1 → 0.2.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/.babelrc +12 -0
- package/.eslintrc.json +139 -0
- package/.storybook/main.js +57 -0
- package/.storybook/manager.js +7 -0
- package/.storybook/preview-head.html +1 -0
- package/.storybook/preview.js +15 -0
- package/.storybook/tsconfig.json +30 -0
- package/jest.config.ts +15 -0
- package/jest.setup.ts +2 -0
- package/package.json +22 -10
- package/project.json +85 -0
- package/src/assets/svg/example_icon.svg +3 -0
- package/src/assets/svg/example_icon_white.svg +3 -0
- package/src/assets/svg/spinner.svg +3 -0
- package/src/assets/svg/spinner_white.svg +3 -0
- package/src/helpers/index.ts +3 -0
- package/src/helpers/talesOf.tsx +42 -0
- package/src/index.ts +2 -0
- package/src/lib/components/README.md +49 -0
- package/src/lib/components/alert-banner/alert-banner.tsx +34 -0
- package/src/lib/components/alert-banner/alert-level-flags.ts +77 -0
- package/src/lib/components/alert-banner/index.ts +1 -0
- package/src/lib/components/badge/badge-type-flags.ts +72 -0
- package/src/lib/components/badge/badge.stories.tsx +16 -0
- package/src/lib/components/badge/badge.test.tsx +29 -0
- package/src/lib/components/badge/badge.tsx +31 -0
- package/src/lib/components/badge/index.ts +1 -0
- package/{lib/components/card/atoms/card-frame.d.ts → src/lib/components/card/atoms/card-frame.tsx} +17 -7
- package/src/lib/components/card/atoms/index.ts +1 -0
- package/src/lib/components/card/card.test.tsx +163 -0
- package/src/lib/components/card/card.tsx +78 -0
- package/src/lib/components/card/components/card-alert-banner-slot.tsx +16 -0
- package/src/lib/components/card/components/card-controls-slot.tsx +19 -0
- package/src/lib/components/card/components/card-section-slot.tsx +51 -0
- package/src/lib/components/card/components/index.ts +3 -0
- package/src/lib/components/card/index.ts +2 -0
- package/src/lib/components/card/molecules/index.ts +1 -0
- package/src/lib/components/card/molecules/left-right-card.test.tsx +89 -0
- package/src/lib/components/card/molecules/left-right-card.tsx +63 -0
- package/src/lib/components/card/storybook/card.stories.mdx +100 -0
- package/src/lib/components/card/storybook/components.tsx +240 -0
- package/src/lib/components/checkbox/checkbox.test.tsx +39 -0
- package/src/lib/components/checkbox/checkbox.tsx +124 -0
- package/src/lib/components/checkbox/components/components.tsx +59 -0
- package/src/lib/components/checkbox/index.tsx +1 -0
- package/src/lib/components/checkbox/stories/checkbox.stories.mdx +54 -0
- package/src/lib/components/checkbox/stories/components.tsx +36 -0
- package/src/lib/components/checkbox/stories/index.tsx +1 -0
- package/src/lib/components/divider/divider-type-flags.tsx +37 -0
- package/src/lib/components/divider/divider.test.tsx +34 -0
- package/src/lib/components/divider/divider.tsx +37 -0
- package/src/lib/components/divider/index.tsx +1 -0
- package/src/lib/components/divider/stories/components.tsx +13 -0
- package/src/lib/components/divider/stories/divider.stories.mdx +50 -0
- package/src/lib/components/index.ts +14 -0
- package/src/lib/components/input-field/components/index.ts +2 -0
- package/src/lib/components/input-field/components/labeled-input.tsx +61 -0
- package/src/lib/components/input-field/components/stepper.tsx +59 -0
- package/src/lib/components/input-field/index.ts +6 -0
- package/src/lib/components/input-field/input-field.test.tsx +108 -0
- package/src/lib/components/input-field/input-field.tsx +126 -0
- package/src/lib/components/input-field/input-number.tsx +41 -0
- package/src/lib/components/input-field/input-text.tsx +30 -0
- package/src/lib/components/input-field/storybook/components.tsx +334 -0
- package/src/lib/components/input-field/storybook/input-field.stories.mdx +113 -0
- package/src/lib/components/layout/flex.tsx +22 -0
- package/src/lib/components/layout/grid-layout.tsx +40 -0
- package/src/lib/components/layout/index.ts +3 -0
- package/src/lib/components/layout/left-right-layout.tsx +67 -0
- package/src/lib/components/link/index.ts +1 -0
- package/src/lib/components/link/link.test.tsx +29 -0
- package/src/lib/components/link/link.tsx +56 -0
- package/src/lib/components/link/storybook/link.stories.mdx +51 -0
- package/src/lib/components/molecules/avatar/avatar-size-flags.tsx +55 -0
- package/src/lib/components/molecules/avatar/avatar.test.tsx +114 -0
- package/src/lib/components/molecules/avatar/avatar.tsx +80 -0
- package/src/lib/components/molecules/avatar/index.tsx +1 -0
- package/src/lib/components/molecules/avatar/stories/avatar.stories.mdx +55 -0
- package/src/lib/components/molecules/avatar/stories/components.tsx +36 -0
- package/src/lib/components/molecules/button/button-flags.tsx +235 -0
- package/src/lib/components/molecules/button/button.test.tsx +77 -0
- package/src/lib/components/molecules/button/button.tsx +231 -0
- package/src/lib/components/molecules/button/index.tsx +1 -0
- package/src/lib/components/molecules/button/stories/button.stories.mdx +104 -0
- package/src/lib/components/molecules/button/stories/components.tsx +86 -0
- package/src/lib/components/molecules/index.ts +3 -0
- package/src/lib/components/molecules/input-checkbox/index.tsx +1 -0
- package/src/lib/components/molecules/input-checkbox/input-checkbox.test.tsx +34 -0
- package/src/lib/components/molecules/input-checkbox/input-checkbox.tsx +50 -0
- package/src/lib/components/molecules/input-checkbox/stories/components.tsx +36 -0
- package/src/lib/components/molecules/input-checkbox/stories/index.tsx +1 -0
- package/src/lib/components/molecules/input-checkbox/stories/input-checkbox.stories.mdx +51 -0
- package/src/lib/components/organisms/index.ts +1 -0
- package/src/lib/components/organisms/multi-choice-list/index.tsx +1 -0
- package/src/lib/components/organisms/multi-choice-list/multi-choice-list.test.tsx +33 -0
- package/src/lib/components/organisms/multi-choice-list/multi-choice-list.tsx +53 -0
- package/src/lib/components/organisms/multi-choice-list/stories/components.tsx +126 -0
- package/src/lib/components/organisms/multi-choice-list/stories/index.tsx +1 -0
- package/src/lib/components/organisms/multi-choice-list/stories/multi-choice-list.stories.mdx +99 -0
- package/src/lib/components/spinner/index.tsx +1 -0
- package/src/lib/components/spinner/spinner-size-flags.tsx +39 -0
- package/src/lib/components/spinner/spinner.test.tsx +31 -0
- package/src/lib/components/spinner/spinner.tsx +67 -0
- package/src/lib/components/spinner/stories/components.tsx +8 -0
- package/src/lib/components/spinner/stories/spinner.stories.mdx +42 -0
- package/src/lib/components/thumbnail/index.tsx +1 -0
- package/src/lib/components/thumbnail/stories/thumbnail.stories.mdx +34 -0
- package/src/lib/components/thumbnail/thumbnail-size-flags.tsx +41 -0
- package/src/lib/components/thumbnail/thumbnail.test.tsx +51 -0
- package/src/lib/components/thumbnail/thumbnail.tsx +40 -0
- package/src/lib/components/typography/index.ts +1 -0
- package/src/lib/components/typography/storybook/components.tsx +256 -0
- package/src/lib/components/typography/storybook/typography.stories.mdx +88 -0
- package/src/lib/components/typography/typography.test.tsx +93 -0
- package/src/lib/components/typography/typography.tsx +57 -0
- package/src/lib/foundations/color-system/base-palette/base-palette.stories.tsx +123 -0
- package/src/lib/foundations/color-system/base-palette/base-palette.ts +94 -0
- package/src/lib/foundations/color-system/base-palette/index.ts +1 -0
- package/src/lib/foundations/color-system/color-guidelines/color-guidelines.stories.mdx +85 -0
- package/src/lib/foundations/color-system/color-guidelines/color-guidelines.stories.tsx +231 -0
- package/src/lib/foundations/color-system/color-guidelines/color-guidelines.ts +159 -0
- package/src/lib/foundations/color-system/color-guidelines/index.ts +1 -0
- package/src/lib/foundations/color-system/components/color-sample.tsx +99 -0
- package/src/lib/foundations/color-system/components/index.ts +1 -0
- package/src/lib/foundations/color-system/index.ts +1 -0
- package/src/lib/foundations/index.ts +4 -0
- package/src/lib/foundations/shadows/components.tsx +59 -0
- package/src/lib/foundations/shadows/index.ts +1 -0
- package/src/lib/foundations/shadows/shadows.stories.mdx +71 -0
- package/src/lib/foundations/shadows/shadows.tsx +47 -0
- package/src/lib/foundations/spacing/index.ts +1 -0
- package/src/lib/foundations/spacing/spacing-guidelines.ts +24 -0
- package/src/lib/foundations/spacing/spacing.stories.mdx +51 -0
- package/src/lib/foundations/spacing/spacing.ts +18 -0
- package/src/lib/foundations/typography/constants.ts +25 -0
- package/src/lib/foundations/typography/index.tsx +1 -0
- package/src/lib/foundations/typography/text-aspect-flags.ts +54 -0
- package/src/lib/foundations/typography/typography.tsx +97 -0
- package/src/lib/helpers/generic-types.ts +44 -0
- package/src/lib/helpers/index.ts +6 -0
- package/src/lib/helpers/nothing.tsx +18 -0
- package/{lib/helpers/numbers.d.ts → src/lib/helpers/numbers.ts} +53 -41
- package/src/lib/helpers/safe-navigation.ts +34 -0
- package/src/lib/helpers/slots.tsx +76 -0
- package/src/lib/helpers/strings.test.ts +47 -0
- package/src/lib/helpers/strings.ts +16 -0
- package/tsconfig.json +35 -0
- package/tsconfig.lib.json +28 -0
- package/tsconfig.spec.json +21 -0
- package/index.d.ts +0 -2
- package/index.js +0 -6078
- package/lib/components/alert-banner/alert-banner.d.ts +0 -11
- package/lib/components/alert-banner/alert-level-flags.d.ts +0 -13
- package/lib/components/alert-banner/index.d.ts +0 -1
- package/lib/components/badge/badge-type-flags.d.ts +0 -18
- package/lib/components/badge/badge.d.ts +0 -5
- package/lib/components/badge/index.d.ts +0 -1
- package/lib/components/card/atoms/index.d.ts +0 -1
- package/lib/components/card/card.d.ts +0 -14
- package/lib/components/card/components/card-alert-banner-slot.d.ts +0 -5
- package/lib/components/card/components/card-controls-slot.d.ts +0 -4
- package/lib/components/card/components/card-section-slot.d.ts +0 -11
- package/lib/components/card/components/index.d.ts +0 -3
- package/lib/components/card/index.d.ts +0 -2
- package/lib/components/card/molecules/index.d.ts +0 -1
- package/lib/components/card/molecules/left-right-card.d.ts +0 -16
- package/lib/components/checkbox/checkbox.d.ts +0 -11
- package/lib/components/checkbox/components/components.d.ts +0 -12
- package/lib/components/checkbox/index.d.ts +0 -1
- package/lib/components/divider/divider-type-flags.d.ts +0 -9
- package/lib/components/divider/divider.d.ts +0 -7
- package/lib/components/divider/index.d.ts +0 -1
- package/lib/components/index.d.ts +0 -12
- package/lib/components/input-field/components/index.d.ts +0 -2
- package/lib/components/input-field/components/labeled-input.d.ts +0 -11
- package/lib/components/input-field/components/stepper.d.ts +0 -7
- package/lib/components/input-field/index.d.ts +0 -3
- package/lib/components/input-field/input-field.d.ts +0 -25
- package/lib/components/input-field/input-number.d.ts +0 -18
- package/lib/components/input-field/input-text.d.ts +0 -14
- package/lib/components/layout/flex.d.ts +0 -16
- package/lib/components/layout/grid-layout.d.ts +0 -11
- package/lib/components/layout/index.d.ts +0 -3
- package/lib/components/layout/left-right-layout.d.ts +0 -70
- package/lib/components/link/index.d.ts +0 -1
- package/lib/components/link/link.d.ts +0 -14
- package/lib/components/molecules/avatar/avatar-size-flags.d.ts +0 -12
- package/lib/components/molecules/avatar/avatar.d.ts +0 -12
- package/lib/components/molecules/avatar/index.d.ts +0 -1
- package/lib/components/molecules/button/button-flags.d.ts +0 -39
- package/lib/components/molecules/button/button.d.ts +0 -24
- package/lib/components/molecules/button/index.d.ts +0 -1
- package/lib/components/molecules/index.d.ts +0 -3
- package/lib/components/molecules/input-checkbox/index.d.ts +0 -1
- package/lib/components/molecules/input-checkbox/input-checkbox.d.ts +0 -8
- package/lib/components/organisms/index.d.ts +0 -1
- package/lib/components/organisms/multi-choice-list/index.d.ts +0 -1
- package/lib/components/organisms/multi-choice-list/multi-choice-list.d.ts +0 -11
- package/lib/components/spinner/index.d.ts +0 -1
- package/lib/components/spinner/spinner-size-flags.d.ts +0 -10
- package/lib/components/spinner/spinner.d.ts +0 -9
- package/lib/components/thumbnail/index.d.ts +0 -1
- package/lib/components/thumbnail/thumbnail-size-flags.d.ts +0 -10
- package/lib/components/thumbnail/thumbnail.d.ts +0 -9
- package/lib/components/typography/index.d.ts +0 -1
- package/lib/components/typography/typography.d.ts +0 -23
- package/lib/foundations/color-system/base-palette/base-palette.d.ts +0 -77
- package/lib/foundations/color-system/base-palette/index.d.ts +0 -1
- package/lib/foundations/color-system/color-guidelines/color-guidelines.d.ts +0 -131
- package/lib/foundations/color-system/color-guidelines/index.d.ts +0 -1
- package/lib/foundations/color-system/components/color-sample.d.ts +0 -17
- package/lib/foundations/color-system/components/index.d.ts +0 -1
- package/lib/foundations/color-system/index.d.ts +0 -1
- package/lib/foundations/index.d.ts +0 -4
- package/lib/foundations/shadows/components.d.ts +0 -8
- package/lib/foundations/shadows/index.d.ts +0 -1
- package/lib/foundations/shadows/shadows.d.ts +0 -8
- package/lib/foundations/spacing/index.d.ts +0 -1
- package/lib/foundations/spacing/spacing-guidelines.d.ts +0 -22
- package/lib/foundations/spacing/spacing.d.ts +0 -18
- package/lib/foundations/typography/constants.d.ts +0 -22
- package/lib/foundations/typography/index.d.ts +0 -1
- package/lib/foundations/typography/text-aspect-flags.d.ts +0 -14
- package/lib/foundations/typography/typography.d.ts +0 -19
- package/lib/helpers/generic-types.d.ts +0 -21
- package/lib/helpers/index.d.ts +0 -6
- package/lib/helpers/nothing.d.ts +0 -8
- package/lib/helpers/safe-navigation.d.ts +0 -14
- package/lib/helpers/slots.d.ts +0 -8
- package/lib/helpers/strings.d.ts +0 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Canvas, Meta } from '@storybook/addon-docs';
|
|
2
|
+
import { Link } from '../link'
|
|
3
|
+
import { Body } from '../../typography'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
<Meta title="Components/Link" />
|
|
7
|
+
|
|
8
|
+
# Link
|
|
9
|
+
|
|
10
|
+
Links are navigational actions that take users to another place. They can appear within or directly following a sentence. Links should not to be mistaken with a Plain Button which are used for actions that aren’t related to navigation.
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## How to use it
|
|
14
|
+
The Link component is an extension of HTML <b><a\></b> tag, but its use is limited to textual anchors.
|
|
15
|
+
|
|
16
|
+
## Default
|
|
17
|
+
|
|
18
|
+
The Link component with default behavior and styles
|
|
19
|
+
<Canvas>
|
|
20
|
+
<Body>
|
|
21
|
+
<Link href="https://app.edvisor.io/" target="_blank" label="Edvisor" /> is the number 1 student recruitment software
|
|
22
|
+
</Body>
|
|
23
|
+
</Canvas>
|
|
24
|
+
|
|
25
|
+
## Subtle
|
|
26
|
+
The Link component with subtle behavior and styles
|
|
27
|
+
<Canvas>
|
|
28
|
+
<Body>
|
|
29
|
+
Streamline the way you sell education with <Link subtle href="https://app.edvisor.io/" target="_blank" label="Edvisor" />, the best student recruitment software.
|
|
30
|
+
</Body>
|
|
31
|
+
</Canvas>
|
|
32
|
+
|
|
33
|
+
## Disabled
|
|
34
|
+
|
|
35
|
+
A disabled Link prevents user interaction.
|
|
36
|
+
<Canvas>
|
|
37
|
+
<Body>
|
|
38
|
+
Education with <Link subtle disabled href="https://app.edvisor.io/" target="_blank" label="Edvisor" /> is the best.
|
|
39
|
+
</Body>
|
|
40
|
+
</Canvas>
|
|
41
|
+
|
|
42
|
+
## API
|
|
43
|
+
|
|
44
|
+
Extends `HTMLAttributes<HTMLAnchorElement>`. Check the documentation <Link href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement" target="_blank" label="here"/>.
|
|
45
|
+
|
|
46
|
+
| Prop | Type | Description |
|
|
47
|
+
| ----------- | --------- | --------------------------|
|
|
48
|
+
| `label` | `string` | the text used as anchor |
|
|
49
|
+
| `default?` | `boolean` | default styling |
|
|
50
|
+
| `subtle?` | `boolean` | subtle styling |
|
|
51
|
+
| `disabled?` | `boolean` | prevents user interaciton |
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// this file was generated, but it is safe to modify
|
|
2
|
+
import { bitwiseOr, MappedEnum, RequireOnlyOne, PropsWithChildren } from '@helpers'
|
|
3
|
+
import { Label1, BodyLarge, Display } from 'components/typography'
|
|
4
|
+
|
|
5
|
+
const enum AvatarSize {
|
|
6
|
+
small = 1,
|
|
7
|
+
medium = 2,
|
|
8
|
+
large = 4,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
type AvatarSizes<T> = MappedEnum<typeof AvatarSize, T>
|
|
12
|
+
|
|
13
|
+
function toAvatarSize(n: number): AvatarSize {
|
|
14
|
+
switch (n) {
|
|
15
|
+
case AvatarSize.small:
|
|
16
|
+
return AvatarSize.small
|
|
17
|
+
case AvatarSize.medium:
|
|
18
|
+
return AvatarSize.medium
|
|
19
|
+
case AvatarSize.large:
|
|
20
|
+
return AvatarSize.large
|
|
21
|
+
default:
|
|
22
|
+
return AvatarSize.medium
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const AvatarSizeValues = {
|
|
27
|
+
[AvatarSize.small]: '32px',
|
|
28
|
+
[AvatarSize.medium]: '40px',
|
|
29
|
+
[AvatarSize.large]: '60px',
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const AvatarSizeNodes = {
|
|
33
|
+
[AvatarSize.small]: Label1,
|
|
34
|
+
[AvatarSize.medium]: BodyLarge,
|
|
35
|
+
[AvatarSize.large]: Display,
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type AvatarSizeProps = Partial<RequireOnlyOne<AvatarSizes<boolean>>> &
|
|
39
|
+
PropsWithChildren
|
|
40
|
+
|
|
41
|
+
export function getValuesBySize(props: AvatarSizeProps): string {
|
|
42
|
+
return AvatarSizeValues[
|
|
43
|
+
toAvatarSize(
|
|
44
|
+
bitwiseOr([props.small, props.medium, props.large])
|
|
45
|
+
)
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function getNodeToRenderText(props: AvatarSizeProps): React.ElementType {
|
|
50
|
+
return AvatarSizeNodes[
|
|
51
|
+
toAvatarSize(
|
|
52
|
+
bitwiseOr([props.small, props.medium, props.large])
|
|
53
|
+
)
|
|
54
|
+
]
|
|
55
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import {render, screen } from '@testing-library/react'
|
|
2
|
+
import { axe } from 'jest-axe'
|
|
3
|
+
import { Avatar } from './index'
|
|
4
|
+
|
|
5
|
+
describe('Avatar Tests', () => {
|
|
6
|
+
describe('Avatar Tests', () => {
|
|
7
|
+
it('should render the acronym name from user', async () => {
|
|
8
|
+
render(
|
|
9
|
+
<Avatar
|
|
10
|
+
name="Some Full Name"
|
|
11
|
+
small
|
|
12
|
+
/>
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
expect(screen.getByText('SN')).toBeInTheDocument()
|
|
16
|
+
expect(screen.queryByRole('img')).not.toBeInTheDocument()
|
|
17
|
+
expect(screen.queryByText('Some Full Name')).not.toBeInTheDocument()
|
|
18
|
+
})
|
|
19
|
+
it('should render the acronym name with just two parts of name', async () => {
|
|
20
|
+
render(
|
|
21
|
+
<Avatar
|
|
22
|
+
name="Some Name"
|
|
23
|
+
small
|
|
24
|
+
/>
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
expect(screen.getByText('SN')).toBeInTheDocument()
|
|
28
|
+
})
|
|
29
|
+
it('should render the acronym name with just one parts of name', async () => {
|
|
30
|
+
render(
|
|
31
|
+
<Avatar
|
|
32
|
+
name="Name"
|
|
33
|
+
small
|
|
34
|
+
/>
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
expect(screen.getByText('N')).toBeInTheDocument()
|
|
38
|
+
})
|
|
39
|
+
it('should not render the acronym with empty name', async () => {
|
|
40
|
+
render(
|
|
41
|
+
<Avatar
|
|
42
|
+
name=""
|
|
43
|
+
small
|
|
44
|
+
/>
|
|
45
|
+
)
|
|
46
|
+
expect(screen.queryByText('Name')).not.toBeInTheDocument()
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
it('should render the image from user', async () => {
|
|
51
|
+
render(
|
|
52
|
+
<Avatar
|
|
53
|
+
name="Some Full Name"
|
|
54
|
+
imageUrl='https://blog.edvisor.io/hubfs/Edvisor%20Smi.png'
|
|
55
|
+
/>
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
expect(screen.queryByText('SN')).not.toBeInTheDocument()
|
|
59
|
+
expect(screen.queryByText('Some Full Name')).not.toBeInTheDocument()
|
|
60
|
+
expect(screen.getByRole('img')).toBeInTheDocument()
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('should not have accessibility issues', async () => {
|
|
64
|
+
const { container } = render(
|
|
65
|
+
<Avatar
|
|
66
|
+
name="Some Full Name"
|
|
67
|
+
small
|
|
68
|
+
/>
|
|
69
|
+
)
|
|
70
|
+
const results = await axe(container)
|
|
71
|
+
expect(results).toHaveNoViolations()
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
describe('withLabel behavior Tests', () => {
|
|
75
|
+
it('should render the full name and the acronym name from user', async () => {
|
|
76
|
+
render(
|
|
77
|
+
<Avatar
|
|
78
|
+
name="Some Full Name"
|
|
79
|
+
withLabel
|
|
80
|
+
/>
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
expect(screen.queryByRole('img')).not.toBeInTheDocument()
|
|
84
|
+
expect(screen.getByText('SN')).toBeInTheDocument()
|
|
85
|
+
expect(screen.getByText('Some Full Name')).toBeInTheDocument()
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('should render the full name and the user image', async () => {
|
|
89
|
+
render(
|
|
90
|
+
<Avatar
|
|
91
|
+
name="Some Full Name"
|
|
92
|
+
imageUrl='https://blog.edvisor.io/hubfs/Edvisor%20Smi.png'
|
|
93
|
+
withLabel
|
|
94
|
+
/>
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
expect(screen.queryByText('SN')).not.toBeInTheDocument()
|
|
98
|
+
expect(screen.getByText('Some Full Name')).toBeInTheDocument()
|
|
99
|
+
expect(screen.getByRole('img')).toBeInTheDocument()
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it('should not have accessibility issues', async () => {
|
|
103
|
+
const { container } = render(
|
|
104
|
+
<Avatar
|
|
105
|
+
name="Some Full Name"
|
|
106
|
+
imageUrl='https://blog.edvisor.io/hubfs/Edvisor%20Smi.png'
|
|
107
|
+
withLabel
|
|
108
|
+
/>
|
|
109
|
+
)
|
|
110
|
+
const results = await axe(container)
|
|
111
|
+
expect(results).toHaveNoViolations()
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
})
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import styled from 'styled-components'
|
|
2
|
+
import { FC, isDefined, isNil, Nothing } from '@helpers'
|
|
3
|
+
import { Margin, Surface } from '@foundations'
|
|
4
|
+
import { SpaceAround } from '../../layout/'
|
|
5
|
+
import { AvatarSizeProps, getValuesBySize, getNodeToRenderText } from './avatar-size-flags'
|
|
6
|
+
import { Label1 } from 'components/typography'
|
|
7
|
+
|
|
8
|
+
const Container = styled(SpaceAround)`
|
|
9
|
+
align-items: center;
|
|
10
|
+
`
|
|
11
|
+
|
|
12
|
+
const Circle = styled.div<{ size: string }>`
|
|
13
|
+
width: ${({ size }) => size};
|
|
14
|
+
height: ${({ size }) => size};
|
|
15
|
+
border-radius: 50%;
|
|
16
|
+
display: flex;
|
|
17
|
+
align-items: center;
|
|
18
|
+
justify-content: space-around;
|
|
19
|
+
background: ${Surface.Neutral.Default};
|
|
20
|
+
`
|
|
21
|
+
|
|
22
|
+
const Image = styled.img`
|
|
23
|
+
width: 100%;
|
|
24
|
+
height: 100%;
|
|
25
|
+
border-radius: 50%;
|
|
26
|
+
`
|
|
27
|
+
|
|
28
|
+
const FullName = styled(Label1)`
|
|
29
|
+
margin-left: ${Margin.xs};
|
|
30
|
+
`
|
|
31
|
+
interface IAvatarProps {
|
|
32
|
+
name: string;
|
|
33
|
+
imageUrl?: string;
|
|
34
|
+
imageLabel?: string;
|
|
35
|
+
withLabel?: boolean;
|
|
36
|
+
className?: string
|
|
37
|
+
}
|
|
38
|
+
type IProps = IAvatarProps & AvatarSizeProps
|
|
39
|
+
|
|
40
|
+
const isFirstOrLast = (el: string,
|
|
41
|
+
index: number,
|
|
42
|
+
items: Array<string>): boolean =>
|
|
43
|
+
isDefined(el) && index === 0 || index === items.length - 1
|
|
44
|
+
|
|
45
|
+
const getInitial = (text: string): string => isNil(text)
|
|
46
|
+
? ''
|
|
47
|
+
: text.charAt(0)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
const getInitialsFromName = (name: string): string => {
|
|
51
|
+
const allNames = name.trim().split(' ')
|
|
52
|
+
const initials = allNames
|
|
53
|
+
.filter(isFirstOrLast)
|
|
54
|
+
.map(getInitial)
|
|
55
|
+
.join('')
|
|
56
|
+
|
|
57
|
+
return initials
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const Avatar: FC<IProps> = (props) => {
|
|
61
|
+
const {name, imageUrl, withLabel, imageLabel = `${name} avatar` } = props
|
|
62
|
+
const size = getValuesBySize(props)
|
|
63
|
+
const Text = getNodeToRenderText(props)
|
|
64
|
+
|
|
65
|
+
if (!isDefined(name)) {
|
|
66
|
+
return <Nothing />
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<Container className={props.className}>
|
|
71
|
+
<Circle size={size}>
|
|
72
|
+
{ isDefined(imageUrl)
|
|
73
|
+
? <Image src={imageUrl} alt={imageLabel}/>
|
|
74
|
+
: <Text>{getInitialsFromName(name)}</Text>
|
|
75
|
+
}
|
|
76
|
+
</Circle>
|
|
77
|
+
{ isDefined(withLabel) && <FullName>{name}</FullName> }
|
|
78
|
+
</Container>
|
|
79
|
+
)
|
|
80
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './avatar'
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Canvas, Meta, Story, ArgsTable } from '@storybook/addon-docs';
|
|
2
|
+
import { Avatar } from '../index'
|
|
3
|
+
import { WrapperStories, AvatarsWithText, AvatarsWithImage, WrapperStoriesWithLabel } from './components'
|
|
4
|
+
|
|
5
|
+
<Meta
|
|
6
|
+
title="Components/Avatar"
|
|
7
|
+
component={Avatar}
|
|
8
|
+
/>
|
|
9
|
+
|
|
10
|
+
# Avatar
|
|
11
|
+
|
|
12
|
+
For more details, check out the component page on [Figma](https://www.figma.com/file/ue1CurHfZ426o2T2l8Dk64/Edvisor-Product-Language?node-id=1008%3A1257)
|
|
13
|
+
|
|
14
|
+
## How to use
|
|
15
|
+
|
|
16
|
+
```javascript
|
|
17
|
+
// Import the component
|
|
18
|
+
import { Avatar } from './index'
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
// Render the component sending the required parameters
|
|
22
|
+
<Avatar name="SOME-NAME-HERE" />
|
|
23
|
+
```
|
|
24
|
+
## Good Practices
|
|
25
|
+
- You can send the `imageLabel` propertie as and `alt` propertie in order to set and alternative text to image
|
|
26
|
+
|
|
27
|
+
## Examples
|
|
28
|
+
|
|
29
|
+
<Canvas>
|
|
30
|
+
<Story name="default">
|
|
31
|
+
<WrapperStories>
|
|
32
|
+
<AvatarsWithText>
|
|
33
|
+
<Avatar name="Yan Leite" small />
|
|
34
|
+
<Avatar name="Yan Leite" medium />
|
|
35
|
+
<Avatar name="Yan Leite" large />
|
|
36
|
+
</AvatarsWithText>
|
|
37
|
+
<AvatarsWithImage>
|
|
38
|
+
<Avatar name="Yan Leite" imageLabel="Edvisor Logo" small imageUrl='https://blog.edvisor.io/hubfs/Edvisor%20Smi.png' />
|
|
39
|
+
<Avatar name="Yan Leite" medium imageUrl='https://blog.edvisor.io/hubfs/Edvisor%20Smi.png' />
|
|
40
|
+
<Avatar name="Yan Leite" large imageUrl='https://blog.edvisor.io/hubfs/Edvisor%20Smi.png' />
|
|
41
|
+
</AvatarsWithImage>
|
|
42
|
+
</WrapperStories>
|
|
43
|
+
</Story>
|
|
44
|
+
</Canvas>
|
|
45
|
+
|
|
46
|
+
Also, we can use that rendering the full name
|
|
47
|
+
<Canvas>
|
|
48
|
+
<Story name="with-label">
|
|
49
|
+
<WrapperStoriesWithLabel>
|
|
50
|
+
<Avatar name="Yan Leite" withLabel />
|
|
51
|
+
<Avatar name="Yan Leite" withLabel imageUrl='https://blog.edvisor.io/hubfs/Edvisor%20Smi.png' />
|
|
52
|
+
</WrapperStoriesWithLabel>
|
|
53
|
+
</Story>
|
|
54
|
+
</Canvas>
|
|
55
|
+
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import styled from 'styled-components'
|
|
2
|
+
import { Surface, Padding } from '@foundations'
|
|
3
|
+
|
|
4
|
+
const WrapperStories = styled.div`
|
|
5
|
+
width: 244px;
|
|
6
|
+
height: 192px;
|
|
7
|
+
background: ${Surface.Default.Default};
|
|
8
|
+
`
|
|
9
|
+
|
|
10
|
+
const WrapperStoriesWithLabel = styled.div`
|
|
11
|
+
width: 130px;
|
|
12
|
+
background: ${Surface.Default.Default};
|
|
13
|
+
|
|
14
|
+
& > div {
|
|
15
|
+
padding-bottom: ${Padding.l};
|
|
16
|
+
}
|
|
17
|
+
`
|
|
18
|
+
|
|
19
|
+
const AvatarsWithText = styled.div`
|
|
20
|
+
display: flex;
|
|
21
|
+
justify-content: space-around;
|
|
22
|
+
padding: ${Padding.l} 0 ${Padding.l} 0;
|
|
23
|
+
`
|
|
24
|
+
|
|
25
|
+
const AvatarsWithImage = styled.div`
|
|
26
|
+
display: flex;
|
|
27
|
+
justify-content: space-around;
|
|
28
|
+
padding-bottom: ${Padding.l};
|
|
29
|
+
`
|
|
30
|
+
|
|
31
|
+
export {
|
|
32
|
+
WrapperStories,
|
|
33
|
+
AvatarsWithText,
|
|
34
|
+
AvatarsWithImage,
|
|
35
|
+
WrapperStoriesWithLabel,
|
|
36
|
+
}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
// this file was generated, but it is safe to modify
|
|
2
|
+
import {
|
|
3
|
+
bitwiseOr,
|
|
4
|
+
MappedEnum,
|
|
5
|
+
RequireOnlyOne,
|
|
6
|
+
PropsWithChildren,
|
|
7
|
+
} from '@helpers'
|
|
8
|
+
import { Actions, Padding, Interactive, Text, Borders } from '@foundations'
|
|
9
|
+
|
|
10
|
+
export const enum ButtonType {
|
|
11
|
+
basic = 1,
|
|
12
|
+
primary = 2,
|
|
13
|
+
primaryDestructive = 4,
|
|
14
|
+
destructive = 8,
|
|
15
|
+
outline = 16,
|
|
16
|
+
plain = 32,
|
|
17
|
+
plainSubtle = 64,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const enum ButtonSize {
|
|
21
|
+
default = 1,
|
|
22
|
+
small = 2,
|
|
23
|
+
large = 4,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const enum ButtonDisabledType {
|
|
27
|
+
enabled = 1,
|
|
28
|
+
disabled = 2,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type ButtonTypes<T> = MappedEnum<typeof ButtonType, T>
|
|
32
|
+
type ButtonSizes<T> = MappedEnum<typeof ButtonSize, T>
|
|
33
|
+
type ButtonDisabledTypes<T> = MappedEnum<typeof ButtonDisabledType, T>
|
|
34
|
+
|
|
35
|
+
function toButtonSize(n: number): ButtonSize {
|
|
36
|
+
switch (n) {
|
|
37
|
+
case ButtonSize.default:
|
|
38
|
+
return ButtonSize.default
|
|
39
|
+
case ButtonSize.small:
|
|
40
|
+
return ButtonSize.small
|
|
41
|
+
case ButtonSize.large:
|
|
42
|
+
return ButtonSize.large
|
|
43
|
+
default:
|
|
44
|
+
return ButtonSize.default
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function toButtonDisabledType(n: number): ButtonDisabledType {
|
|
49
|
+
switch (n) {
|
|
50
|
+
case ButtonDisabledType.enabled:
|
|
51
|
+
return ButtonDisabledType.enabled
|
|
52
|
+
case ButtonDisabledType.disabled:
|
|
53
|
+
return ButtonDisabledType.disabled
|
|
54
|
+
default:
|
|
55
|
+
return ButtonDisabledType.enabled
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const ButtonBackgroundColorValues = {
|
|
60
|
+
[ButtonType.basic]: Actions.Secondary.Default,
|
|
61
|
+
[ButtonType.primary]: Actions.Primary.Default,
|
|
62
|
+
[ButtonType.primaryDestructive]: Actions.Critical.Default,
|
|
63
|
+
[ButtonType.destructive]: 'none',
|
|
64
|
+
[ButtonType.outline]: 'none',
|
|
65
|
+
[ButtonType.plain]: 'none',
|
|
66
|
+
[ButtonType.plainSubtle]: 'none',
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const ButtonBackgroundColorDisabledValues = {
|
|
70
|
+
[ButtonType.basic]: Actions.Secondary.Disabled,
|
|
71
|
+
[ButtonType.primary]: Actions.Primary.Disabled,
|
|
72
|
+
[ButtonType.primaryDestructive]: Actions.Critical.Disabled,
|
|
73
|
+
[ButtonType.destructive]: Actions.Secondary.Disabled,
|
|
74
|
+
[ButtonType.outline]: 'none',
|
|
75
|
+
[ButtonType.plain]: 'none',
|
|
76
|
+
[ButtonType.plainSubtle]: 'none',
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const ButtonBackgroundColorHoverValues = {
|
|
80
|
+
[ButtonType.basic]: Actions.Secondary.Hover,
|
|
81
|
+
[ButtonType.primary]: Actions.Primary.Hover,
|
|
82
|
+
[ButtonType.primaryDestructive]: Actions.Critical.Hover,
|
|
83
|
+
[ButtonType.destructive]: Actions.Critical.Hover,
|
|
84
|
+
[ButtonType.outline]: Actions.Secondary.Hover,
|
|
85
|
+
[ButtonType.plain]: '',
|
|
86
|
+
[ButtonType.plainSubtle]: '',
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const ButtonBackgroundColorPressedValues = {
|
|
90
|
+
[ButtonType.basic]: Actions.Secondary.Pressed,
|
|
91
|
+
[ButtonType.primary]: Actions.Primary.Pressed,
|
|
92
|
+
[ButtonType.primaryDestructive]: Actions.Critical.Pressed,
|
|
93
|
+
[ButtonType.destructive]: Actions.Critical.Pressed,
|
|
94
|
+
[ButtonType.outline]: Actions.Secondary.Pressed,
|
|
95
|
+
[ButtonType.plain]: Actions.Secondary.Hover,
|
|
96
|
+
[ButtonType.plainSubtle]: Actions.Secondary.Hover,
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const ButtonTextColorValues = {
|
|
100
|
+
[ButtonType.basic]: Text.Default,
|
|
101
|
+
[ButtonType.primary]: Text.OnPrimary,
|
|
102
|
+
[ButtonType.primaryDestructive]: Text.OnCritical,
|
|
103
|
+
[ButtonType.destructive]: Text.Default,
|
|
104
|
+
[ButtonType.outline]: Text.Default,
|
|
105
|
+
[ButtonType.plain]: Interactive.Default.Default,
|
|
106
|
+
[ButtonType.plainSubtle]: Interactive.Subtle.Default,
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const ButtonTextColorHoverValues = {
|
|
110
|
+
[ButtonType.basic]: Text.Default,
|
|
111
|
+
[ButtonType.primary]: Text.OnPrimary,
|
|
112
|
+
[ButtonType.primaryDestructive]: Text.OnCritical,
|
|
113
|
+
[ButtonType.destructive]: Text.OnCritical,
|
|
114
|
+
[ButtonType.outline]: Text.Default,
|
|
115
|
+
[ButtonType.plain]: Interactive.Default.Hover,
|
|
116
|
+
[ButtonType.plainSubtle]: Interactive.Subtle.Hover,
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const ButtonBorderValues = {
|
|
120
|
+
[ButtonType.basic]: `1px solid ${Borders.Default.Default}`,
|
|
121
|
+
[ButtonType.primary]: 'none',
|
|
122
|
+
[ButtonType.primaryDestructive]: 'none',
|
|
123
|
+
[ButtonType.destructive]: `1px solid ${Borders.Default.Default}`,
|
|
124
|
+
[ButtonType.outline]: `1px solid ${Borders.Default.Default}`,
|
|
125
|
+
[ButtonType.plain]: 'none',
|
|
126
|
+
[ButtonType.plainSubtle]: 'none',
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const ButtonBorderDisabledValues = {
|
|
130
|
+
[ButtonType.basic]: `1px solid ${Borders.Default.Subdued}`,
|
|
131
|
+
[ButtonType.primary]: 'none',
|
|
132
|
+
[ButtonType.primaryDestructive]: 'none',
|
|
133
|
+
[ButtonType.destructive]: `1px solid ${Borders.Default.Subdued}`,
|
|
134
|
+
[ButtonType.outline]: `1px solid ${Borders.Default.Default}`,
|
|
135
|
+
[ButtonType.plain]: 'none',
|
|
136
|
+
[ButtonType.plainSubtle]: 'none',
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const ButtonTextColorDisabled = {
|
|
140
|
+
[ButtonDisabledType.enabled]: '',
|
|
141
|
+
[ButtonDisabledType.disabled]: Text.Light,
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const ButtonCursor = {
|
|
145
|
+
[ButtonDisabledType.enabled]: 'pointer',
|
|
146
|
+
[ButtonDisabledType.disabled]: 'not-allowed',
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const ButtonSizeValues = {
|
|
150
|
+
[ButtonSize.small]: `${Padding.xxs} ${Padding.s}`,
|
|
151
|
+
[ButtonSize.default]: `${Padding.xs} ${Padding.m}`,
|
|
152
|
+
[ButtonSize.large]: `${Padding.s} ${Padding.l}`,
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const ButtonSizeValuesByType = {
|
|
156
|
+
[ButtonType.basic]: '',
|
|
157
|
+
[ButtonType.primary]: '',
|
|
158
|
+
[ButtonType.primaryDestructive]: '',
|
|
159
|
+
[ButtonType.destructive]: '',
|
|
160
|
+
[ButtonType.outline]: '',
|
|
161
|
+
[ButtonType.plain]: `${Padding.xxxs} ${Padding.xxs}`,
|
|
162
|
+
[ButtonType.plainSubtle]: `${Padding.xxxs} ${Padding.xxs}`,
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export type ButtonTypeProps = Partial<RequireOnlyOne<ButtonTypes<boolean>>> &
|
|
166
|
+
PropsWithChildren
|
|
167
|
+
|
|
168
|
+
export type ButtonSizeProps = Partial<RequireOnlyOne<ButtonSizes<boolean>>> &
|
|
169
|
+
PropsWithChildren
|
|
170
|
+
|
|
171
|
+
export type ButtonDisabledTypeProps = Partial<
|
|
172
|
+
RequireOnlyOne<ButtonDisabledTypes<boolean>>
|
|
173
|
+
> &
|
|
174
|
+
PropsWithChildren
|
|
175
|
+
|
|
176
|
+
export function getBackgroundColorByType(type: ButtonType): string {
|
|
177
|
+
return ButtonBackgroundColorValues[type]
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export function getBackgroundColorHoverByType(type: ButtonType): string {
|
|
181
|
+
return ButtonBackgroundColorHoverValues[type]
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export function getBackgroundColorDisabledByType(type: ButtonType): string {
|
|
185
|
+
return ButtonBackgroundColorDisabledValues[type]
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function getBackgroundColorPressedByType(type: ButtonType): string {
|
|
189
|
+
return ButtonBackgroundColorPressedValues[type]
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export function getTextColorByType(type: ButtonType): string {
|
|
193
|
+
return ButtonTextColorValues[type]
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export function getTextColorOnHoverByType(type: ButtonType): string {
|
|
197
|
+
return ButtonTextColorHoverValues[type]
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export function getBorderByType(type: ButtonType): string {
|
|
201
|
+
return ButtonBorderValues[type]
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export function getBorderDisabledByType(type: ButtonType): string {
|
|
205
|
+
return ButtonBorderDisabledValues[type]
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export function getPaddingBySize(props: ButtonSizeProps): string {
|
|
209
|
+
return ButtonSizeValues[
|
|
210
|
+
toButtonSize(bitwiseOr([props.default, props.small, props.large]))
|
|
211
|
+
]
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export function getPaddingByType(type: ButtonType): string {
|
|
215
|
+
return ButtonSizeValuesByType[type]
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export function getTextColorIfDisabled(props: ButtonDisabledTypeProps): string {
|
|
219
|
+
return ButtonTextColorDisabled[
|
|
220
|
+
toButtonDisabledType(bitwiseOr([props.enabled, props.disabled]))
|
|
221
|
+
]
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export function getCursor(props: ButtonDisabledTypeProps): string {
|
|
225
|
+
return ButtonCursor[
|
|
226
|
+
toButtonDisabledType(bitwiseOr([props.enabled, props.disabled]))
|
|
227
|
+
]
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export function getIsDisabled(props: ButtonDisabledTypeProps): boolean {
|
|
231
|
+
return (
|
|
232
|
+
toButtonDisabledType(bitwiseOr([props.enabled, props.disabled])) ===
|
|
233
|
+
ButtonDisabledType.disabled
|
|
234
|
+
)
|
|
235
|
+
}
|