@bitrise/bitkit 9.35.2 → 9.36.0-alpha-avatar.1
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/README.md +27 -12
- package/package.json +1 -1
- package/src/Components/Avatar/Avatar.stories.tsx +15 -0
- package/src/Components/Avatar/Avatar.theme.ts +66 -0
- package/src/Components/Avatar/Avatar.tsx +24 -0
- package/src/index.ts +2 -0
- package/src/old.ts +0 -3
- package/src/theme.ts +2 -0
- package/src/tsconfig.tsbuildinfo +1 -1
package/README.md
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
# @bitrise/bitkit
|
|
2
2
|
|
|
3
3
|
Library for React UI components and design patterns.
|
|
4
|
-
|
|
5
|
-
Based on [Chakra UI](https://chakra-ui.com/).
|
|
6
4
|
___
|
|
7
5
|
|
|
8
6
|
|
|
@@ -16,29 +14,46 @@ yarn install
|
|
|
16
14
|
|
|
17
15
|
### Technology
|
|
18
16
|
|
|
19
|
-
- [Chakra UI](https://chakra-ui.com/)
|
|
20
17
|
- [Typescript](https://www.typescriptlang.org/)
|
|
21
|
-
- [
|
|
18
|
+
- [Parcel](https://parceljs.org/) (bundler and dev servers)
|
|
19
|
+
- [React](https://reactjs.org/) (with [React Router](https://reacttraining.com/react-router/) for routing links)
|
|
20
|
+
- [PostCSS](https://postcss.org/) (with [postcss-preset-env](https://preset-env.cssdb.org/) for a little power)
|
|
22
21
|
- [Jest](https://jestjs.io/) (for unit testing)
|
|
23
22
|
|
|
23
|
+
### Managing icons
|
|
24
|
+
|
|
25
|
+
If you would like to add a new or edit an existing icon:
|
|
26
|
+
1. Export the icon from [Figma](https://www.figma.com/file/grik9mTaJ5DfhydhWhXdP5/Bitkit-Foundations?node-id=213%3A82) as an SVG. Make sure that the exported file has the following viewBox: `0 0 24 24`, otherwise the icon can make smaller or bigger compared to the existing ones.
|
|
27
|
+
2. Rename the file using this convention: `icons-{iconName}.svg` (eg.: `icons-crown.svg`)
|
|
28
|
+
3. Add the file under the `./src/components/Icon/svg` folder.
|
|
29
|
+
4. If you are not running `yarn start`, run the `yarn build:icons` script to generate the React component from the SVG. You should commit both the `.svg` and the generated `.tsx` files.
|
|
30
|
+
5. Make sure to check the new/update icon on the Icons page.
|
|
24
31
|
### Scripts
|
|
25
32
|
|
|
26
|
-
#### `$ yarn
|
|
33
|
+
#### `$ yarn build`
|
|
27
34
|
|
|
28
|
-
|
|
35
|
+
Builds the library and styleguide assets
|
|
29
36
|
|
|
30
|
-
#### `$ yarn
|
|
37
|
+
#### `$ yarn build:icons`
|
|
31
38
|
|
|
32
|
-
|
|
39
|
+
Uses **[@svgr/cli](https://github.com/smooth-code/svgr)** to generate React components and Typescript definitions inside `./src/components/Icon/tsx` from the SVG files inside `./src/components/Icon/svg`.
|
|
40
|
+
|
|
41
|
+
#### `$ yarn clean`
|
|
42
|
+
|
|
43
|
+
Cleans up the build directories
|
|
33
44
|
|
|
34
45
|
#### `$ yarn lint`
|
|
35
46
|
|
|
36
47
|
Runs Javascript linting
|
|
37
48
|
|
|
38
|
-
#### `$ yarn
|
|
49
|
+
#### `$ yarn serve`
|
|
39
50
|
|
|
40
|
-
|
|
51
|
+
Serves up the static files built for the style guide
|
|
52
|
+
|
|
53
|
+
#### `$ yarn start`
|
|
41
54
|
|
|
42
|
-
|
|
55
|
+
Runs the developlement server for the style guide
|
|
43
56
|
|
|
44
|
-
|
|
57
|
+
#### `$ yarn test`
|
|
58
|
+
|
|
59
|
+
Runs the unit tests for the library components
|
package/package.json
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ComponentStory, ComponentMeta } from '@storybook/react';
|
|
2
|
+
import Avatar from './Avatar';
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
title: 'Components/Avatar',
|
|
6
|
+
component: Avatar,
|
|
7
|
+
} as ComponentMeta<typeof Avatar>;
|
|
8
|
+
|
|
9
|
+
export const WithProps: ComponentStory<typeof Avatar> = ({ contentProps, ...props }) => <Avatar {...props} />;
|
|
10
|
+
|
|
11
|
+
WithProps.args = {
|
|
12
|
+
...Avatar.defaultProps,
|
|
13
|
+
name: 'Bitrise website',
|
|
14
|
+
src: 'https://bitrise-public-content-production.s3.amazonaws.com/org-icons/default_avatar-02.png',
|
|
15
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { ComponentStyleConfig } from '@chakra-ui/theme';
|
|
2
|
+
import { AvatarSizes } from './Avatar';
|
|
3
|
+
|
|
4
|
+
const BACKGROUND_COLORS = [
|
|
5
|
+
'#68442c',
|
|
6
|
+
'#86d641',
|
|
7
|
+
'#a775db',
|
|
8
|
+
'#df5ac3',
|
|
9
|
+
'#46bee8',
|
|
10
|
+
'#63c99a',
|
|
11
|
+
'#19937c',
|
|
12
|
+
'#ed544c',
|
|
13
|
+
'#ff931e',
|
|
14
|
+
'#107ec1',
|
|
15
|
+
'#48e1ed',
|
|
16
|
+
'#743da5',
|
|
17
|
+
'#f9d128',
|
|
18
|
+
'#ff931e',
|
|
19
|
+
'#9e4b39',
|
|
20
|
+
'#b51c98',
|
|
21
|
+
'#b20202',
|
|
22
|
+
'#bf8a66',
|
|
23
|
+
'#2c3f50',
|
|
24
|
+
'#441f62',
|
|
25
|
+
'#0c5b4c',
|
|
26
|
+
'#391401',
|
|
27
|
+
'#27ae61',
|
|
28
|
+
'#ef7bef',
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
const getSize = (size: AvatarSizes) => {
|
|
32
|
+
const sizeAsNumber = Number(size);
|
|
33
|
+
const fontSizes = {
|
|
34
|
+
16: '9px',
|
|
35
|
+
24: '1',
|
|
36
|
+
32: '3',
|
|
37
|
+
40: '3',
|
|
38
|
+
48: '4',
|
|
39
|
+
64: '5',
|
|
40
|
+
96: '7',
|
|
41
|
+
128: '8',
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
fontSize: fontSizes[sizeAsNumber as keyof typeof fontSizes],
|
|
46
|
+
height: `${sizeAsNumber / 16}rem`,
|
|
47
|
+
width: `${sizeAsNumber / 16}rem`,
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const AvatarTheme: ComponentStyleConfig = {
|
|
52
|
+
baseStyle: ({ name, size }) => {
|
|
53
|
+
const str = name.toUpperCase();
|
|
54
|
+
const seed = str.charCodeAt(0) + str.charCodeAt(str.length - 1);
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
container: {
|
|
58
|
+
backgroundColor: BACKGROUND_COLORS[seed % BACKGROUND_COLORS.length],
|
|
59
|
+
color: 'neutral.100',
|
|
60
|
+
...getSize(size),
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export default AvatarTheme;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Avatar as ChakraAvatar, AvatarProps as ChakraAvatarProps, forwardRef } from '@chakra-ui/react';
|
|
2
|
+
import { Radii } from '../../Foundations/Radii/Radii';
|
|
3
|
+
|
|
4
|
+
export type AvatarSizes = '16' | '24' | '32' | '40' | '48' | '64' | '96' | '128';
|
|
5
|
+
|
|
6
|
+
export interface AvatarProps extends ChakraAvatarProps {
|
|
7
|
+
borderRadius?: keyof Radii;
|
|
8
|
+
size?: AvatarSizes;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const getInitials = (name: string) => {
|
|
12
|
+
return `${name.charAt(0)}${name.charAt(name.length - 1)}`;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const Avatar = forwardRef<AvatarProps, 'span'>((props, ref) => (
|
|
16
|
+
<ChakraAvatar getInitials={getInitials} {...props} ref={ref} />
|
|
17
|
+
));
|
|
18
|
+
|
|
19
|
+
Avatar.defaultProps = {
|
|
20
|
+
borderRadius: '8',
|
|
21
|
+
size: '32',
|
|
22
|
+
} as AvatarProps;
|
|
23
|
+
|
|
24
|
+
export default Avatar;
|
package/src/index.ts
CHANGED
|
@@ -110,3 +110,5 @@ export { default as PopoverTrigger } from './Components/Popover/PopoverTrigger';
|
|
|
110
110
|
export type { PopoverContentProps } from './Components/Popover/PopoverContent';
|
|
111
111
|
export { default as PopoverContent } from './Components/Popover/PopoverContent';
|
|
112
112
|
|
|
113
|
+
export type { AvatarProps } from './Components/Avatar/Avatar';
|
|
114
|
+
export { default as Avatar } from './Components/Avatar/Avatar';
|
package/src/old.ts
CHANGED
|
@@ -34,9 +34,6 @@ export { default as AppLayoutMain } from './Old/AppLayout/AppLayoutMain';
|
|
|
34
34
|
export type { Props as AppLayoutSidebarProps } from './Old/AppLayout/AppLayoutSidebar';
|
|
35
35
|
export { default as AppLayoutSidebar } from './Old/AppLayout/AppLayoutSidebar';
|
|
36
36
|
|
|
37
|
-
export type { Props as AvatarProps } from './Old/Avatar/Avatar';
|
|
38
|
-
export { default as Avatar } from './Old/Avatar/Avatar';
|
|
39
|
-
|
|
40
37
|
export type { Props as BaseProps } from './Old/Base/Base';
|
|
41
38
|
export type { TypeBorderRadius } from './Old/Base/Base';
|
|
42
39
|
export type { TypeColors } from './Old/Base/Base';
|
package/src/theme.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import Avatar from './Components/Avatar/Avatar.theme';
|
|
1
2
|
import Badge from './Components/Badge/Badge.theme';
|
|
2
3
|
import Button from './Components/Button/Button.theme';
|
|
3
4
|
import Card from './Components/Card/Card.theme';
|
|
@@ -59,6 +60,7 @@ const theme = {
|
|
|
59
60
|
},
|
|
60
61
|
},
|
|
61
62
|
components: {
|
|
63
|
+
Avatar,
|
|
62
64
|
Badge,
|
|
63
65
|
Button,
|
|
64
66
|
Card,
|