@gv-tech/design-system 0.8.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.
Files changed (88) hide show
  1. package/.github/CODEOWNERS +2 -0
  2. package/.github/CONTRIBUTING.md +38 -0
  3. package/.github/FUNDING.yml +4 -0
  4. package/.github/PULL_REQUEST_TEMPLATE/build.md +5 -0
  5. package/.github/PULL_REQUEST_TEMPLATE/standard.md +3 -0
  6. package/.github/RELEASING.md +37 -0
  7. package/.github/copilot-instructions.md +93 -0
  8. package/.github/workflows/ci.yml +82 -0
  9. package/.github/workflows/codeql-analysis.yml +34 -0
  10. package/.github/workflows/release-please.yml +53 -0
  11. package/.husky/pre-commit +1 -0
  12. package/.nvmrc +1 -0
  13. package/.prettierignore +1 -0
  14. package/.storybook/.preview-head.html +1 -0
  15. package/.storybook/main.ts +38 -0
  16. package/.storybook/preview.tsx +30 -0
  17. package/.tool-versions +1 -0
  18. package/.vscode/launch.json +22 -0
  19. package/.vscode/settings.json +30 -0
  20. package/.yarn/releases/yarn-4.12.0.cjs +942 -0
  21. package/.yarnrc.yml +7 -0
  22. package/CHANGELOG.md +490 -0
  23. package/LICENSE +21 -0
  24. package/README.md +116 -0
  25. package/SECURITY.md +9 -0
  26. package/babel.config.js +3 -0
  27. package/dist/favicon.ico +0 -0
  28. package/dist/index.demo.html +40 -0
  29. package/dist/index.js +647 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/index.mjs +1053 -0
  32. package/dist/index.mjs.map +1 -0
  33. package/dist/logo192.png +0 -0
  34. package/dist/logo512.png +0 -0
  35. package/dist/manifest.json +25 -0
  36. package/dist/robots.txt +2 -0
  37. package/dist/vendor-DXgJBoQh.mjs +265 -0
  38. package/dist/vendor-DXgJBoQh.mjs.map +1 -0
  39. package/dist/vendor-nZSsnGb7.js +7 -0
  40. package/dist/vendor-nZSsnGb7.js.map +1 -0
  41. package/docs/MIGRATE_TO_GVTECH_SCOPE.md +74 -0
  42. package/eslint.config.mjs +95 -0
  43. package/netlify.toml +6 -0
  44. package/package.json +130 -0
  45. package/public/favicon.ico +0 -0
  46. package/public/index.demo.html +40 -0
  47. package/public/logo192.png +0 -0
  48. package/public/logo512.png +0 -0
  49. package/public/manifest.json +25 -0
  50. package/public/robots.txt +2 -0
  51. package/scripts/validate.js +56 -0
  52. package/serve.json +4 -0
  53. package/src/Avatar.stories.tsx +67 -0
  54. package/src/Avatar.tsx +174 -0
  55. package/src/Badge.stories.tsx +87 -0
  56. package/src/Badge.tsx +76 -0
  57. package/src/Button.stories.tsx +244 -0
  58. package/src/Button.tsx +384 -0
  59. package/src/Icon.stories.tsx +101 -0
  60. package/src/Icon.tsx +64 -0
  61. package/src/Intro.stories.tsx +20 -0
  62. package/src/Link.stories.tsx +69 -0
  63. package/src/Link.tsx +252 -0
  64. package/src/StoryLinkWrapper.d.ts +1 -0
  65. package/src/StoryLinkWrapper.tsx +33 -0
  66. package/src/__tests__/Avatar.test.tsx +28 -0
  67. package/src/__tests__/Badge.test.tsx +25 -0
  68. package/src/__tests__/Button.test.tsx +38 -0
  69. package/src/__tests__/Icon.test.tsx +26 -0
  70. package/src/__tests__/Link.test.tsx +31 -0
  71. package/src/index.ts +13 -0
  72. package/src/mdx.d.ts +5 -0
  73. package/src/setupTests.ts +1 -0
  74. package/src/shared/animation.d.ts +18 -0
  75. package/src/shared/animation.js +60 -0
  76. package/src/shared/global.d.ts +12 -0
  77. package/src/shared/global.js +120 -0
  78. package/src/shared/icons.d.ts +34 -0
  79. package/src/shared/icons.js +282 -0
  80. package/src/shared/styles.d.ts +86 -0
  81. package/src/shared/styles.js +98 -0
  82. package/src/test-utils/axe.ts +25 -0
  83. package/src/types.ts +316 -0
  84. package/tsconfig.build.json +12 -0
  85. package/tsconfig.json +20 -0
  86. package/tsconfig.node.json +10 -0
  87. package/vite.config.ts +35 -0
  88. package/vitest.config.ts +13 -0
package/package.json ADDED
@@ -0,0 +1,130 @@
1
+ {
2
+ "name": "@gv-tech/design-system",
3
+ "version": "0.8.0",
4
+ "description": "Garcia Ventures react design system",
5
+ "license": "MIT",
6
+ "author": "Eric N. Garcia <eng618@garciaericn.com>",
7
+ "main": "dist/index.cjs.js",
8
+ "module": "dist/index.es.js",
9
+ "types": "dist/index.d.ts",
10
+ "repository": "git@github.com:Garcia-ventures/gvtech-design.git",
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "engines": {
15
+ "node": ">=20"
16
+ },
17
+ "scripts": {
18
+ "build": "tsc -p tsconfig.build.json && vite build",
19
+ "build-storybook": "storybook build",
20
+ "build-storybook-docs": "storybook build --docs",
21
+ "dev": "vite dev",
22
+ "format": "prettier --write .",
23
+ "format:ci": "prettier --check .",
24
+ "lint": "eslint . --cache",
25
+ "lint:fix": "eslint . --cache --fix",
26
+ "lint:report": "eslint . --cache -o ./eslintReport.html -f html",
27
+ "prepare": "husky",
28
+ "start": "vite dev",
29
+ "storybook": "storybook dev -p 9009",
30
+ "serve": "yarn build-storybook && yarn dlx serve storybook-static -l 6006",
31
+ "test": "vitest",
32
+ "test:ci": "CI=true vitest --run --reporter=dot",
33
+ "test:watch": "vitest --watch",
34
+ "test-storybook": "test-storybook",
35
+ "test-storybook:ci": "concurrently -k -s first -n \"SB,TEST\" \"yarn dlx serve storybook-static -p 6006\" \"wait-on http://127.0.0.1:6006 && test-storybook --url http://127.0.0.1:6006\"",
36
+ "validate": "node ./scripts/validate.js",
37
+ "validate:fix": "node ./scripts/validate.js --fix"
38
+ },
39
+ "peerDependencies": {
40
+ "polished": "^4.0.0",
41
+ "prop-types": "^15.8.0",
42
+ "react": "^18 || ^19",
43
+ "react-dom": "^18 || ^19",
44
+ "react-is": "^16 || ^17 || ^18 || ^19",
45
+ "styled-components": "^5 || ^6"
46
+ },
47
+ "devDependencies": {
48
+ "@babel/cli": "^7.28.6",
49
+ "@babel/core": "^7.28.6",
50
+ "@babel/preset-env": "^7.28.6",
51
+ "@babel/preset-react": "^7.28.5",
52
+ "@babel/preset-typescript": "^7.28.5",
53
+ "@eng618/prettier-config": "^2.5.2",
54
+ "@eslint/js": "^9.39.2",
55
+ "@mdx-js/react": "^3.1.1",
56
+ "@storybook/addon-a11y": "10.2.1",
57
+ "@storybook/addon-docs": "10.2.1",
58
+ "@storybook/addon-links": "10.2.1",
59
+ "@storybook/builder-vite": "10.2.1",
60
+ "@storybook/cli": "10.2.1",
61
+ "@storybook/jest": "^0.2.3",
62
+ "@storybook/react-vite": "10.2.1",
63
+ "@storybook/test-runner": "^0.24.2",
64
+ "@storybook/testing-library": "^0.2.2",
65
+ "@testing-library/dom": "^10.4.1",
66
+ "@testing-library/jest-dom": "^6.9.1",
67
+ "@testing-library/react": "^16.3.2",
68
+ "@testing-library/user-event": "^14.6.1",
69
+ "@types/react": "^19.2.10",
70
+ "@types/react-dom": "^19.2.3",
71
+ "@typescript-eslint/eslint-plugin": "^8.54.0",
72
+ "@typescript-eslint/parser": "^8.54.0",
73
+ "@vitejs/plugin-react": "5.1.2",
74
+ "axe-core": "^4.7.2",
75
+ "babel-loader": "^10.0.0",
76
+ "concurrently": "^9.2.1",
77
+ "eslint": "^9.39.2",
78
+ "eslint-config-prettier": "^10.1.8",
79
+ "eslint-plugin-jsx-a11y": "^6.10.2",
80
+ "eslint-plugin-prettier": "^5.5.5",
81
+ "eslint-plugin-react": "^7.37.5",
82
+ "eslint-plugin-react-hooks": "^7.0.1",
83
+ "eslint-plugin-storybook": "10.2.1",
84
+ "globals": "^17.2.0",
85
+ "husky": "^9.1.7",
86
+ "jsdom": "^27.4.0",
87
+ "lint-staged": "^16.2.7",
88
+ "polished": "^4.3.1",
89
+ "prettier": "^3.8.1",
90
+ "prop-types": "^15.8.1",
91
+ "react": "^19.2.4",
92
+ "react-docgen-typescript": "^2.4.0",
93
+ "react-dom": "^19.2.4",
94
+ "react-is": "^19.2.4",
95
+ "storybook": "10.2.1",
96
+ "styled-components": "^6.3.8",
97
+ "typescript": "^5.9.3",
98
+ "vite": "7.3.1",
99
+ "vitest": "^4.0.18",
100
+ "wait-on": "^9.0.3"
101
+ },
102
+ "lint-staged": {
103
+ "*.(js|ts|mjs|cjs)?(x)": [
104
+ "prettier --write",
105
+ "eslint --cache --fix"
106
+ ],
107
+ "*.(md)?(x)": [
108
+ "prettier --write"
109
+ ]
110
+ },
111
+ "prettier": "@eng618/prettier-config",
112
+ "babel": {
113
+ "presets": [
114
+ "@babel/preset-env",
115
+ "@babel/preset-react"
116
+ ]
117
+ },
118
+ "browserslist": {
119
+ "development": [
120
+ "last 1 chrome version",
121
+ "last 1 firefox version",
122
+ "last 1 safari version"
123
+ ],
124
+ "production": [
125
+ ">0.2%",
126
+ "not dead"
127
+ ]
128
+ },
129
+ "packageManager": "yarn@4.12.0"
130
+ }
Binary file
@@ -0,0 +1,40 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
7
+ <meta name="theme-color" content="#000000" />
8
+ <meta name="description" content="Garcia Ventures design system" />
9
+ <link rel="apple-touch-icon" href="logo192.png" />
10
+ <!--
11
+ manifest.json provides metadata used when your web app is installed on a
12
+ user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
13
+ -->
14
+ <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
15
+ <!--
16
+ Notice the use of %PUBLIC_URL% in the tags above.
17
+ It will be replaced with the URL of the `public` folder during the build.
18
+ Only files inside the `public` folder can be referenced from the HTML.
19
+
20
+ Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
21
+ work correctly both with client-side routing and a non-root public URL.
22
+ Learn how to configure a non-root public URL by running `npm run build`.
23
+ -->
24
+ <title>GV Tech Design System</title>
25
+ </head>
26
+ <body>
27
+ <noscript>You need to enable JavaScript to run this app.</noscript>
28
+ <div id="root"></div>
29
+ <!--
30
+ This HTML file is a template.
31
+ If you open it directly in the browser, you will see an empty page.
32
+
33
+ You can add webfonts, meta tags, or analytics to this file.
34
+ The build step will place the bundled scripts into the <body> tag.
35
+
36
+ To begin the development, run `npm start` or `yarn start`.
37
+ To create a production bundle, use `npm run build` or `yarn build`.
38
+ -->
39
+ </body>
40
+ </html>
Binary file
Binary file
@@ -0,0 +1,25 @@
1
+ {
2
+ "short_name": "GV Design",
3
+ "name": "GV Tech Design System",
4
+ "icons": [
5
+ {
6
+ "src": "favicon.ico",
7
+ "sizes": "64x64 32x32 24x24 16x16",
8
+ "type": "image/x-icon"
9
+ },
10
+ {
11
+ "src": "logo192.png",
12
+ "type": "image/png",
13
+ "sizes": "192x192"
14
+ },
15
+ {
16
+ "src": "logo512.png",
17
+ "type": "image/png",
18
+ "sizes": "512x512"
19
+ }
20
+ ],
21
+ "start_url": ".",
22
+ "display": "standalone",
23
+ "theme_color": "#000000",
24
+ "background_color": "#ffffff"
25
+ }
@@ -0,0 +1,2 @@
1
+ # https://www.robotstxt.org/robotstxt.html
2
+ User-agent: *
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { spawnSync } = require('child_process');
4
+
5
+ const args = process.argv.slice(2);
6
+ const fix = args.includes('--fix');
7
+
8
+ const steps = [
9
+ {
10
+ name: fix ? 'Prettier fix' : 'Prettier check',
11
+ cmd: fix ? 'yarn format' : 'yarn format:ci',
12
+ },
13
+ {
14
+ name: fix ? 'Lint fix (eslint)' : 'Lint (eslint)',
15
+ cmd: fix ? 'yarn lint:fix' : 'yarn lint',
16
+ },
17
+ { name: 'TypeScript type check', cmd: 'npx tsc --noEmit' },
18
+ { name: 'Build (vite)', cmd: 'yarn build' },
19
+ { name: 'Storybook build', cmd: 'yarn build-storybook' },
20
+ { name: 'Storybook docs build', cmd: 'yarn build-storybook-docs' },
21
+ ];
22
+
23
+ const SEP = '------------------------------------------------------------';
24
+ const green = (s) => `\x1b[32m${s}\x1b[0m`;
25
+ const red = (s) => `\x1b[31m${s}\x1b[0m`;
26
+ const yellow = (s) => `\x1b[33m${s}\x1b[0m`;
27
+
28
+ console.log(SEP);
29
+ console.log('\x1b[1mRunning validate steps (sequential)\x1b[0m');
30
+ console.log(SEP);
31
+
32
+ for (const step of steps) {
33
+ console.log(yellow(`\n> ${step.name}`));
34
+ console.log(yellow(`> ${step.cmd}\n`));
35
+
36
+ const result = spawnSync(step.cmd, { stdio: 'inherit', shell: true });
37
+
38
+ if (result.error) {
39
+ console.error(red(`\nFailed to run: ${step.cmd}`));
40
+ console.error(red(result.error));
41
+ process.exit(1);
42
+ }
43
+
44
+ if (result.status !== 0) {
45
+ console.error(red(`\n${step.name} failed with exit code ${result.status}.`));
46
+ console.error(red('Stopping further steps.'));
47
+ process.exit(result.status || 1);
48
+ }
49
+
50
+ console.log(green(`\n${step.name} succeeded.`));
51
+ }
52
+
53
+ console.log('\n' + SEP);
54
+ console.log(green('All validate steps completed successfully ✅'));
55
+ console.log(SEP + '\n');
56
+ process.exit(0);
package/serve.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "cleanUrls": false,
3
+ "trailingSlash": false
4
+ }
@@ -0,0 +1,67 @@
1
+ import { Meta, StoryObj } from '@storybook/react-vite';
2
+ import { Avatar } from './Avatar';
3
+
4
+ const meta: Meta<typeof Avatar> = {
5
+ title: 'Design System/Avatar',
6
+ component: Avatar,
7
+ argTypes: {
8
+ loading: {
9
+ control: 'boolean',
10
+ description: 'Use the loading state to indicate that the data Avatar needs is still loading.',
11
+ },
12
+ username: {
13
+ description:
14
+ "Avatar falls back to the user's initial when no image is provided. Supply a `username` and omit `src` to see what this looks like.",
15
+ },
16
+ src: {
17
+ description: "The URL of the Avatar's image.",
18
+ },
19
+ size: {
20
+ description: "Avatar comes in four sizes. In most cases, you'll be fine with `medium`.",
21
+ },
22
+ },
23
+ };
24
+
25
+ export default meta;
26
+ type Story = StoryObj<typeof meta>;
27
+
28
+ import { expect } from '@storybook/jest';
29
+ import { within } from '@storybook/testing-library';
30
+
31
+ export const Standard: Story = {
32
+ args: {
33
+ username: 'John Doe',
34
+ },
35
+ play: async ({ canvasElement }) => {
36
+ const canvas = within(canvasElement);
37
+ const avatar = canvas.getByLabelText('John Doe');
38
+ expect(avatar).toBeInTheDocument();
39
+ expect(avatar).toHaveTextContent('J');
40
+ },
41
+ };
42
+
43
+ export const Loading: Story = {
44
+ args: {
45
+ loading: true,
46
+ username: 'Loading',
47
+ },
48
+ play: async ({ canvasElement }) => {
49
+ const canvas = within(canvasElement);
50
+ const avatar = canvas.getByLabelText('Loading avatar ...');
51
+ expect(avatar).toBeInTheDocument();
52
+ // In loading state, it might show a placeholder or nothing specific
53
+ },
54
+ };
55
+
56
+ export const WithImage: Story = {
57
+ args: {
58
+ src: 'https://avatars.githubusercontent.com/u/1?v=4',
59
+ username: 'GitHub',
60
+ },
61
+ play: async ({ canvasElement }) => {
62
+ const canvas = within(canvasElement);
63
+ const img = canvas.getByRole('img');
64
+ expect(img).toBeInTheDocument();
65
+ expect(img).toHaveAttribute('src', 'https://avatars.githubusercontent.com/u/1?v=4');
66
+ },
67
+ };
package/src/Avatar.tsx ADDED
@@ -0,0 +1,174 @@
1
+ import React from 'react';
2
+ import styled, { css } from 'styled-components';
3
+ import { color, typography } from './shared/styles';
4
+ import { glow } from './shared/animation';
5
+ import { Icon } from './Icon';
6
+
7
+ /**
8
+ * Available avatar sizes with their pixel values
9
+ */
10
+ export const sizes = {
11
+ large: 40,
12
+ medium: 28,
13
+ small: 20,
14
+ tiny: 16,
15
+ } as const;
16
+
17
+ /**
18
+ * Union type for avatar size keys
19
+ */
20
+ export type AvatarSize = keyof typeof sizes;
21
+
22
+ /**
23
+ * Props for the Avatar component
24
+ */
25
+ interface AvatarProps extends React.HTMLAttributes<HTMLDivElement> {
26
+ /** Whether the avatar is in a loading state */
27
+ loading?: boolean;
28
+ /** The username to display (used for initials or alt text) */
29
+ username?: string;
30
+ /** Image source URL for the avatar */
31
+ src?: string;
32
+ /** Size variant of the avatar */
33
+ size?: AvatarSize;
34
+ }
35
+
36
+ /**
37
+ * Props for styled Image component
38
+ */
39
+ interface ImageProps {
40
+ loading?: boolean;
41
+ size?: AvatarSize;
42
+ src?: string;
43
+ }
44
+
45
+ /**
46
+ * Props for styled Initial component
47
+ */
48
+ interface InitialProps {
49
+ size?: AvatarSize;
50
+ }
51
+
52
+ const Image = styled.div<ImageProps>`
53
+ background: ${(props) => (!props.loading ? 'transparent' : color.light)};
54
+ border-radius: 50%;
55
+ display: inline-block;
56
+ vertical-align: top;
57
+ overflow: hidden;
58
+ text-transform: uppercase;
59
+
60
+ height: ${sizes.medium}px;
61
+ width: ${sizes.medium}px;
62
+ line-height: ${sizes.medium}px;
63
+
64
+ ${(props) =>
65
+ props.size === 'tiny' &&
66
+ css`
67
+ height: ${sizes.tiny}px;
68
+ width: ${sizes.tiny}px;
69
+ line-height: ${sizes.tiny}px;
70
+ `}
71
+
72
+ ${(props) =>
73
+ props.size === 'small' &&
74
+ css`
75
+ height: ${sizes.small}px;
76
+ width: ${sizes.small}px;
77
+ line-height: ${sizes.small}px;
78
+ `}
79
+
80
+ ${(props) =>
81
+ props.size === 'large' &&
82
+ css`
83
+ height: ${sizes.large}px;
84
+ width: ${sizes.large}px;
85
+ line-height: ${sizes.large}px;
86
+ `}
87
+
88
+ ${(props) =>
89
+ !props.src &&
90
+ css`
91
+ background: ${!props.loading && '#37D5D3'};
92
+ `}
93
+
94
+ img {
95
+ width: 100%;
96
+ height: auto;
97
+ display: block;
98
+ }
99
+
100
+ svg {
101
+ position: relative;
102
+ bottom: -2px;
103
+ height: 100%;
104
+ width: 100%;
105
+ vertical-align: top;
106
+ }
107
+
108
+ path {
109
+ fill: ${color.medium};
110
+ animation: ${glow} 1.5s ease-in-out infinite;
111
+ }
112
+ `;
113
+
114
+ // prettier-ignore
115
+ const Initial = styled.div<InitialProps>`
116
+ color: ${color.lightest};
117
+ text-align: center;
118
+
119
+ font-size: ${typography.size.s2}px;
120
+ line-height: ${sizes.medium}px;
121
+
122
+ ${(props) => props.size === 'tiny' && css`
123
+ font-size: ${Number(typography.size.s1) - 2}px;
124
+ line-height: ${sizes.tiny}px;
125
+ `}
126
+
127
+ ${(props) => props.size === 'small' && css`
128
+ font-size: ${typography.size.s1}px;
129
+ line-height: ${sizes.small}px;
130
+ `}
131
+
132
+ ${(props) => props.size === 'large' && css`
133
+ font-size: ${typography.size.s3}px;
134
+ line-height: ${sizes.large}px;
135
+ `}
136
+ `;
137
+
138
+ /**
139
+ * Avatar component for displaying user profile images or initials
140
+ *
141
+ * @example
142
+ * ```tsx
143
+ * <Avatar username="John Doe" size="large" />
144
+ * <Avatar src="https://example.com/avatar.jpg" username="Jane Doe" />
145
+ * <Avatar loading username="Loading..." />
146
+ * ```
147
+ */
148
+ export const Avatar = ({ loading = false, username = 'loading', src, size = 'medium', ...props }: AvatarProps) => {
149
+ let avatarFigure = <Icon icon="useralt" block={false} />;
150
+ const a11yProps: {
151
+ 'aria-busy'?: boolean;
152
+ 'aria-label'?: string;
153
+ } = {};
154
+
155
+ if (loading) {
156
+ a11yProps['aria-busy'] = true;
157
+ a11yProps['aria-label'] = 'Loading avatar ...';
158
+ } else if (src) {
159
+ avatarFigure = <img src={src} alt={username} />;
160
+ } else {
161
+ a11yProps['aria-label'] = username;
162
+ avatarFigure = (
163
+ <Initial size={size} aria-hidden="true">
164
+ {username.substring(0, 1)}
165
+ </Initial>
166
+ );
167
+ }
168
+
169
+ return (
170
+ <Image size={size} loading={loading} src={src} {...a11yProps} {...props}>
171
+ {avatarFigure}
172
+ </Image>
173
+ );
174
+ };
@@ -0,0 +1,87 @@
1
+ import type { ReactNode } from 'react';
2
+ import { Meta, StoryObj } from '@storybook/react-vite';
3
+
4
+ import { Badge } from './Badge';
5
+ import { Icon } from './Icon';
6
+
7
+ const meta: Meta<typeof Badge> = {
8
+ title: 'Design System/Badge',
9
+ component: Badge,
10
+ };
11
+
12
+ import { expect } from '@storybook/jest';
13
+ import { within } from '@storybook/testing-library';
14
+
15
+ export default meta;
16
+ type Story = StoryObj<typeof meta>;
17
+
18
+ export const AllBadges: Story = {
19
+ args: {
20
+ children: 'Badge',
21
+ },
22
+ render: (_args) => (
23
+ <div>
24
+ <Badge status="positive">Positive</Badge>
25
+ <Badge status="negative">Negative</Badge>
26
+ <Badge status="neutral">Neutral</Badge>
27
+ <Badge status="error">Error</Badge>
28
+ <Badge status="warning">Warning</Badge>
29
+ <Badge status="positive">
30
+ <Icon icon="facehappy" inline block={false} />
31
+ with icon
32
+ </Badge>
33
+ </div>
34
+ ),
35
+ };
36
+
37
+ export const Positive: Story = {
38
+ render: () => <Badge status="positive">Positive</Badge>,
39
+ };
40
+ export const Negative = () => <Badge status="negative">Negative</Badge>;
41
+ export const Warning = () => <Badge status="warning">Warning</Badge>;
42
+ export const Neutral = () => <Badge status="neutral">Neutral</Badge>;
43
+ export const Error = () => <Badge status="error">Error</Badge>;
44
+
45
+ interface BadgeArgs {
46
+ status?: 'positive' | 'negative' | 'neutral' | 'error' | 'warning';
47
+ children?: ReactNode;
48
+ }
49
+
50
+ interface IconArgs {
51
+ icon: string;
52
+ inline?: boolean;
53
+ block: boolean;
54
+ }
55
+
56
+ type WithIconArgs = BadgeArgs & IconArgs;
57
+
58
+ export const WithIcon = (args: WithIconArgs) => (
59
+ <Badge {...args}>
60
+ <Icon {...args} />
61
+ with icon
62
+ </Badge>
63
+ );
64
+ WithIcon.args = {
65
+ status: 'warning',
66
+ icon: 'check',
67
+ inline: true,
68
+ block: false,
69
+ };
70
+
71
+ WithIcon.storyName = 'with icon';
72
+ WithIcon.play = async ({ canvasElement }: { canvasElement: HTMLElement }) => {
73
+ const canvas = within(canvasElement);
74
+ const badge = canvas.getByText(/with icon/i);
75
+ expect(badge).toBeInTheDocument();
76
+ const icon = canvasElement.querySelector('svg');
77
+ expect(icon).toBeInTheDocument();
78
+ };
79
+
80
+ AllBadges.play = async ({ canvasElement }: { canvasElement: HTMLElement }) => {
81
+ const canvas = within(canvasElement);
82
+ expect(canvas.getByText('Positive')).toBeInTheDocument();
83
+ expect(canvas.getByText('Negative')).toBeInTheDocument();
84
+ expect(canvas.getByText('Neutral')).toBeInTheDocument();
85
+ expect(canvas.getByText('Error')).toBeInTheDocument();
86
+ expect(canvas.getByText('Warning')).toBeInTheDocument();
87
+ };
package/src/Badge.tsx ADDED
@@ -0,0 +1,76 @@
1
+ import styled, { css } from 'styled-components';
2
+ import { background, color, typography } from './shared/styles';
3
+ import { BadgeProps, BADGE_STATUSES, StatusProps } from './types';
4
+
5
+ /**
6
+ * Styled badge wrapper with status-based styling
7
+ */
8
+ const BadgeWrapper = styled.div<StatusProps>`
9
+ display: inline-block;
10
+ vertical-align: top;
11
+ font-size: 11px;
12
+ line-height: 12px;
13
+ padding: 4px 12px;
14
+ border-radius: 3em;
15
+ font-weight: ${typography.weight.bold};
16
+
17
+ svg {
18
+ height: 12px;
19
+ width: 12px;
20
+ margin-right: 4px;
21
+ margin-top: -2px;
22
+ }
23
+
24
+ ${(props) =>
25
+ props.status === BADGE_STATUSES.POSITIVE &&
26
+ css`
27
+ color: ${color.positive};
28
+ background: ${background.positive};
29
+ `};
30
+
31
+ ${(props) =>
32
+ props.status === BADGE_STATUSES.NEGATIVE &&
33
+ css`
34
+ color: ${color.negative};
35
+ background: ${background.negative};
36
+ `};
37
+
38
+ ${(props) =>
39
+ props.status === BADGE_STATUSES.WARNING &&
40
+ css`
41
+ color: ${color.warning};
42
+ background: ${background.warning};
43
+ `};
44
+
45
+ ${(props) =>
46
+ props.status === BADGE_STATUSES.ERROR &&
47
+ css`
48
+ color: ${color.lightest};
49
+ background: ${color.negative};
50
+ `};
51
+
52
+ ${(props) =>
53
+ props.status === BADGE_STATUSES.NEUTRAL &&
54
+ css`
55
+ color: ${color.dark};
56
+ background: ${color.mediumlight};
57
+ `};
58
+ `;
59
+
60
+ /**
61
+ * Badge component for displaying status indicators and labels
62
+ *
63
+ * @example
64
+ * ```tsx
65
+ * <Badge status="positive">Success</Badge>
66
+ * <Badge status="error">Error</Badge>
67
+ * <Badge>Default</Badge>
68
+ * ```
69
+ */
70
+ export const Badge = ({ status = BADGE_STATUSES.NEUTRAL, children, ...props }: BadgeProps) => {
71
+ return (
72
+ <BadgeWrapper status={status} {...props}>
73
+ {children}
74
+ </BadgeWrapper>
75
+ );
76
+ };