@indico-data/design-system 2.45.6 → 2.46.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/lib/components/badge/Badge.d.ts +2 -0
- package/lib/components/badge/Badge.stories.d.ts +7 -0
- package/lib/components/badge/__tests__/Badge.test.d.ts +1 -0
- package/lib/components/badge/index.d.ts +1 -0
- package/lib/components/badge/types.d.ts +7 -0
- package/lib/components/index.d.ts +1 -0
- package/lib/components/menu/Menu.d.ts +2 -1
- package/lib/index.css +55 -0
- package/lib/index.d.ts +13 -2
- package/lib/index.esm.css +55 -0
- package/lib/index.esm.js +13 -4
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +13 -3
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/badge/Badge.mdx +36 -0
- package/src/components/badge/Badge.stories.tsx +109 -0
- package/src/components/badge/Badge.tsx +18 -0
- package/src/components/badge/__tests__/Badge.test.tsx +17 -0
- package/src/components/badge/index.ts +1 -0
- package/src/components/badge/styles/Badge.scss +61 -0
- package/src/components/badge/types.ts +8 -0
- package/src/components/card/Card.tsx +1 -1
- package/src/components/index.ts +1 -0
- package/src/components/menu/Menu.tsx +3 -2
- package/src/index.ts +1 -1
- package/src/styles/index.scss +1 -0
package/package.json
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Canvas, Meta, Controls, Story } from '@storybook/blocks';
|
|
2
|
+
import * as Badge from './Badge.stories';
|
|
3
|
+
import { Container, Row, Col } from '../grid';
|
|
4
|
+
import { fas } from '@fortawesome/free-solid-svg-icons';
|
|
5
|
+
import { registerFontAwesomeIcons } from '@/setup/setupIcons';
|
|
6
|
+
import { indiconDefinitions } from '@/components/icons/indicons';
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
<Meta title="Components/Badge" name="Badge" of={Badge} />
|
|
10
|
+
|
|
11
|
+
# Badge
|
|
12
|
+
The Badge component is designed to display concise information about an item. It is versatile and can be used in various contexts, such as within dropdowns or other interactive elements.
|
|
13
|
+
|
|
14
|
+
<Canvas of={Badge.String} />
|
|
15
|
+
|
|
16
|
+
### The following props are available for the Badge component:
|
|
17
|
+
|
|
18
|
+
<Controls of={Badge.String} />
|
|
19
|
+
|
|
20
|
+
<Container>
|
|
21
|
+
<Row>
|
|
22
|
+
<Col xs={12}>
|
|
23
|
+
<h2 >Usage</h2>
|
|
24
|
+
</Col>
|
|
25
|
+
<Col sm={6}>
|
|
26
|
+
<h3>String</h3>
|
|
27
|
+
<p>The string prop is used to display a string inside the badge.</p>
|
|
28
|
+
<Canvas of={Badge.String} />
|
|
29
|
+
</Col>
|
|
30
|
+
<Col sm={6}>
|
|
31
|
+
<h3>With Dropdown</h3>
|
|
32
|
+
<p>The dropdown prop is used to display a dropdown inside the badge as a child element.</p>
|
|
33
|
+
<Canvas of={Badge.WithDropdown} />
|
|
34
|
+
</Col>
|
|
35
|
+
</Row>
|
|
36
|
+
</Container>
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { Badge } from './Badge';
|
|
3
|
+
import { Col, Container, Row } from '../grid';
|
|
4
|
+
import { FloatUI } from '../floatUI';
|
|
5
|
+
import { Menu } from '../menu';
|
|
6
|
+
import { Icon } from '../icons';
|
|
7
|
+
|
|
8
|
+
const meta: Meta = {
|
|
9
|
+
title: 'Components/Badge',
|
|
10
|
+
component: Badge,
|
|
11
|
+
argTypes: {
|
|
12
|
+
size: {
|
|
13
|
+
control: 'select',
|
|
14
|
+
options: ['xs', 'sm', 'md', 'lg', 'xl'],
|
|
15
|
+
description: 'The size of the badge',
|
|
16
|
+
table: {
|
|
17
|
+
category: 'Props',
|
|
18
|
+
type: {
|
|
19
|
+
summary: 'string',
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
className: {
|
|
24
|
+
control: 'text',
|
|
25
|
+
description: 'Additional classes for the badge component',
|
|
26
|
+
table: {
|
|
27
|
+
category: 'Props',
|
|
28
|
+
type: {
|
|
29
|
+
summary: 'string',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
children: {
|
|
34
|
+
control: false,
|
|
35
|
+
description: 'The content of the badge (superseded by the string prop)',
|
|
36
|
+
table: {
|
|
37
|
+
category: 'Props',
|
|
38
|
+
type: {
|
|
39
|
+
summary: 'React.ReactNode',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
string: {
|
|
44
|
+
control: 'text',
|
|
45
|
+
description: 'The string to display in the badge. (supersedes children prop)',
|
|
46
|
+
table: {
|
|
47
|
+
category: 'Props',
|
|
48
|
+
type: {
|
|
49
|
+
summary: 'string',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export default meta;
|
|
57
|
+
|
|
58
|
+
type Story = StoryObj<typeof Badge>;
|
|
59
|
+
|
|
60
|
+
export const String: Story = {
|
|
61
|
+
args: {
|
|
62
|
+
className: '',
|
|
63
|
+
string: 'Badge',
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
render: (args) => {
|
|
67
|
+
return (
|
|
68
|
+
<Container>
|
|
69
|
+
<Row>
|
|
70
|
+
<Col sm={4}>
|
|
71
|
+
<Badge {...args} />
|
|
72
|
+
</Col>
|
|
73
|
+
</Row>
|
|
74
|
+
</Container>
|
|
75
|
+
);
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export const WithDropdown: Story = {
|
|
80
|
+
args: {
|
|
81
|
+
className: '',
|
|
82
|
+
size: 'sm',
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
render: (args) => {
|
|
86
|
+
return (
|
|
87
|
+
<Container>
|
|
88
|
+
<Row>
|
|
89
|
+
<Col sm={4} style={{ height: '130px' }}>
|
|
90
|
+
<Badge {...args}>
|
|
91
|
+
<FloatUI ariaLabel="Badge">
|
|
92
|
+
<div style={{ display: 'flex', alignItems: 'center', cursor: 'pointer' }}>
|
|
93
|
+
<p className="text-overline">Badge</p>
|
|
94
|
+
<Icon size="xs" className="ml-3" name="chevron-down" />
|
|
95
|
+
</div>
|
|
96
|
+
<Menu className="pa-2">
|
|
97
|
+
<li>Item 1</li>
|
|
98
|
+
<li>Item 2</li>
|
|
99
|
+
<li>Item 3</li>
|
|
100
|
+
<li>Item 4</li>
|
|
101
|
+
</Menu>
|
|
102
|
+
</FloatUI>
|
|
103
|
+
</Badge>
|
|
104
|
+
</Col>
|
|
105
|
+
</Row>
|
|
106
|
+
</Container>
|
|
107
|
+
);
|
|
108
|
+
},
|
|
109
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import { BadgeProps } from './types';
|
|
3
|
+
|
|
4
|
+
export const Badge = ({ className = '', children, size = 'md', string, ...rest }: BadgeProps) => {
|
|
5
|
+
const badgeClasses = classNames(
|
|
6
|
+
'badge',
|
|
7
|
+
{
|
|
8
|
+
[`badge--${size}`]: size,
|
|
9
|
+
},
|
|
10
|
+
className,
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<div className={badgeClasses} {...rest}>
|
|
15
|
+
{string ? <p>{string}</p> : children}
|
|
16
|
+
</div>
|
|
17
|
+
);
|
|
18
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import { Badge } from '@/components/badge/Badge';
|
|
3
|
+
|
|
4
|
+
describe('Badge', () => {
|
|
5
|
+
it.each(['xs', 'sm', 'md', 'lg', 'xl'] as const)('renders the badge with size %s', (size) => {
|
|
6
|
+
render(<Badge size={size}>Badge</Badge>);
|
|
7
|
+
expect(screen.getByText('Badge')).toHaveClass(`badge--${size}`);
|
|
8
|
+
});
|
|
9
|
+
it('renders the badge with content inside', () => {
|
|
10
|
+
render(<Badge>Badge</Badge>);
|
|
11
|
+
expect(screen.getByText('Badge')).toBeInTheDocument();
|
|
12
|
+
});
|
|
13
|
+
it('renders the badge with string', () => {
|
|
14
|
+
render(<Badge string="Badge" />);
|
|
15
|
+
expect(screen.getByText('Badge')).toBeInTheDocument();
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Badge } from './Badge';
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Common Variables
|
|
2
|
+
:root {
|
|
3
|
+
--pf-badge-rounded: var(--pf-rounded);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
// Light Theme Specific Variables
|
|
7
|
+
:root [data-theme='light'] {
|
|
8
|
+
--pf-badge-background-color: var(--pf-white-color);
|
|
9
|
+
--pf-badge-border-color: var(--pf-border-color);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Dark Theme Specific Variables
|
|
13
|
+
:root [data-theme='dark'],
|
|
14
|
+
:root {
|
|
15
|
+
--pf-badge-background-color: var(--pf-primary-color-600);
|
|
16
|
+
--pf-badge-border-color: var(--pf-border-color);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.badge {
|
|
20
|
+
border-radius: var(--pf-rounded-lg);
|
|
21
|
+
padding: var(--pf-padding-3);
|
|
22
|
+
background: var(--pf-badge-background-color);
|
|
23
|
+
border: var(--pf-border-sm) solid var(--pf-badge-border-color);
|
|
24
|
+
box-sizing: border-box;
|
|
25
|
+
width: fit-content;
|
|
26
|
+
|
|
27
|
+
&--xs {
|
|
28
|
+
padding: var(--pf-padding-1);
|
|
29
|
+
p {
|
|
30
|
+
font-size: var(--pf-font-size-overline);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
&--sm {
|
|
35
|
+
padding: var(--pf-padding-2);
|
|
36
|
+
p {
|
|
37
|
+
font-size: var(--pf-font-size-body2);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
&--md {
|
|
42
|
+
padding: var(--pf-padding-3);
|
|
43
|
+
p {
|
|
44
|
+
font-size: var(--pf-font-size-body);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
&--lg {
|
|
49
|
+
padding: var(--pf-padding-4);
|
|
50
|
+
p {
|
|
51
|
+
font-size: var(--pf-font-size-h2);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
&--xl {
|
|
56
|
+
padding: var(--pf-padding-5);
|
|
57
|
+
p {
|
|
58
|
+
font-size: var(--pf-font-size-h1);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
package/src/components/index.ts
CHANGED
|
@@ -18,3 +18,4 @@ export { DatePicker } from './forms/date/datePicker/DatePicker';
|
|
|
18
18
|
export { IconTriggerDatePicker } from './forms/date/iconTriggerDatePicker';
|
|
19
19
|
export { SingleInputDatePicker } from './forms/date/inputDatePicker';
|
|
20
20
|
export { InputDateRangePicker } from './forms/date/inputDateRangePicker';
|
|
21
|
+
export { Badge } from './badge';
|
|
@@ -3,11 +3,12 @@ import classNames from 'classnames';
|
|
|
3
3
|
|
|
4
4
|
export type MenuProps = {
|
|
5
5
|
children: React.ReactNode;
|
|
6
|
+
className?: string;
|
|
6
7
|
};
|
|
7
8
|
|
|
8
|
-
export function Menu({ children }: MenuProps) {
|
|
9
|
+
export function Menu({ children, className, ...rest }: MenuProps) {
|
|
9
10
|
return (
|
|
10
|
-
<div className=
|
|
11
|
+
<div className={classNames('menu', className)} {...rest}>
|
|
11
12
|
{React.Children.map(children, (child) =>
|
|
12
13
|
React.isValidElement(child)
|
|
13
14
|
? React.cloneElement(child as ReactElement, {
|
package/src/index.ts
CHANGED
|
@@ -13,7 +13,6 @@ export {
|
|
|
13
13
|
Tooltip,
|
|
14
14
|
} from './legacy/components';
|
|
15
15
|
|
|
16
|
-
// New Components
|
|
17
16
|
export { Container, Row, Col } from './components/grid';
|
|
18
17
|
export { Button } from './components/button';
|
|
19
18
|
export { Icon } from './components/icons';
|
|
@@ -34,6 +33,7 @@ export { Card } from './components/card';
|
|
|
34
33
|
export { FloatUI } from './components/floatUI';
|
|
35
34
|
export { Menu } from './components/menu';
|
|
36
35
|
export { Pill } from './components/pill';
|
|
36
|
+
export { Badge } from './components/badge';
|
|
37
37
|
|
|
38
38
|
// Utilities
|
|
39
39
|
export { registerFontAwesomeIcons } from './setup/setupIcons';
|
package/src/styles/index.scss
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
@import '../components/menu/styles/Menu.scss';
|
|
22
22
|
@import '../components/floatUI/styles/FloatUI.scss';
|
|
23
23
|
@import '../components/forms/date/datePicker/styles/DatePicker.scss';
|
|
24
|
+
@import '../components/badge/styles/Badge.scss';
|
|
24
25
|
|
|
25
26
|
@import '../components/pill/styles/Pill.scss';
|
|
26
27
|
@import 'sheets'; // Port to an sheets component when we build it
|