Skip to content

Commit e0e49d1

Browse files
committed
Migrate Avatar and Badge
1 parent 9af616f commit e0e49d1

File tree

5 files changed

+67
-20
lines changed

5 files changed

+67
-20
lines changed

packages/main/src/webComponents/Avatar/Avatar.stories.tsx

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,38 @@ import { AvatarFitType } from '@ui5/webcomponents-react/lib/AvatarFitType';
55
import { AvatarShape } from '@ui5/webcomponents-react/lib/AvatarShape';
66
import { AvatarSize } from '@ui5/webcomponents-react/lib/AvatarSize';
77
import React from 'react';
8+
import { createSelectArgTypes } from '@shared/stories/createSelectArgTypes';
89

910
export default {
1011
title: 'UI5 Web Components / Avatar',
11-
component: Avatar
12+
component: Avatar,
13+
argTypes: {
14+
...createSelectArgTypes({
15+
backgroundColor: AvatarBackgroundColor,
16+
imageFitType: AvatarFitType,
17+
shape: AvatarShape,
18+
size: AvatarSize
19+
})
20+
},
21+
args: {
22+
backgroundColor: AvatarBackgroundColor.Accent6,
23+
icon: 'employee',
24+
imageFitType: AvatarFitType.Cover,
25+
shape: AvatarShape.Circle,
26+
size: AvatarSize.S
27+
}
1228
};
1329

14-
export const generatedDefaultStory = () => (
30+
export const generatedDefaultStory = (props) => (
1531
<Avatar
16-
backgroundColor={select('backgroundColor', AvatarBackgroundColor, AvatarBackgroundColor.Accent6)}
17-
icon={text('icon', 'employee')}
18-
image={text('image', '')}
19-
imageFitType={select('imageFitType', AvatarFitType, AvatarFitType.Cover)}
20-
initials={text('initials', '')}
21-
shape={select('shape', AvatarShape, AvatarShape.Circle)}
22-
size={select('size', AvatarSize, AvatarSize.S)}
23-
accessibleName={text('accessibleName', '')}
32+
backgroundColor={props.backgroundColor}
33+
icon={props.icon}
34+
image={props.image}
35+
imageFitType={props.imageFitType}
36+
initials={props.initials}
37+
shape={props.shape}
38+
size={props.size}
39+
accessibleName={props.accessibleName}
2440
/>
2541
);
2642

packages/main/src/webComponents/Badge/Badge.stories.tsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
1-
import { text } from '@storybook/addon-knobs';
21
import { Badge } from '@ui5/webcomponents-react/lib/Badge';
2+
import { Icon } from '@ui5/webcomponents-react/lib/Icon';
33
import React from 'react';
44

55
export default {
66
title: 'UI5 Web Components / Badge',
7-
component: Badge
7+
component: Badge,
8+
argTypes: {
9+
colorScheme: {
10+
control: {
11+
type: 'number',
12+
min: 1,
13+
max: 10
14+
}
15+
}
16+
},
17+
args: {
18+
colorScheme: 1,
19+
children: 'Some Content'
20+
}
821
};
922

10-
export const generatedDefaultStory = () => (
11-
<Badge colorScheme={text('colorScheme', '1')} icon={null}>
12-
Some Content
23+
export const generatedDefaultStory = (props) => (
24+
<Badge colorScheme={props.colorScheme} icon={<Icon name="add" />}>
25+
{props.children}
1326
</Badge>
1427
);
1528

packages/main/src/webComponents/Badge/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { withWebComponent } from '@ui5/webcomponents-react/lib/withWebComponent';
22
import '@ui5/webcomponents/dist/Badge';
3-
import React, { FC, ReactNode } from 'react';
3+
import React, { FC, ReactElement, ReactNode } from 'react';
44
import { WithWebComponentPropTypes } from '../../internal/withWebComponent';
55

66
export interface BadgePropTypes extends WithWebComponentPropTypes {
@@ -15,7 +15,7 @@ export interface BadgePropTypes extends WithWebComponentPropTypes {
1515
/**
1616
* Defines the <code>ui5-icon</code> to be displayed in the <code>ui5-badge</code>.
1717
*/
18-
icon?: ReactNode | ReactNode[];
18+
icon?: ReactElement;
1919
}
2020

2121
/**

packages/main/src/webComponents/Button/Button.stories.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { createSelectArgTypes } from '@shared/stories/createSelectArgTypes';
12
import { Button } from '@ui5/webcomponents-react/lib/Button';
23
import { ButtonDesign } from '@ui5/webcomponents-react/lib/ButtonDesign';
34
import React from 'react';
@@ -6,9 +7,7 @@ export default {
67
title: 'UI5 Web Components / Button',
78
component: Button,
89
argTypes: {
9-
design: {
10-
control: { type: 'options', controlType: 'select', options: ButtonDesign }
11-
},
10+
...createSelectArgTypes({ design: ButtonDesign }),
1211
onClick: { control: { type: 'function' } }
1312
},
1413
args: {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
type ArgDefinition = {
2+
[key: string]: Record<string, string>;
3+
};
4+
5+
export const createSelectArgTypes = (definition: ArgDefinition) => {
6+
const argTypes = {};
7+
8+
for (let arg in definition) {
9+
argTypes[arg] = {
10+
control: {
11+
type: 'options',
12+
controlType: 'select',
13+
options: definition[arg]
14+
}
15+
};
16+
}
17+
18+
return argTypes;
19+
};

0 commit comments

Comments
 (0)