Skip to content

Commit 2dc2013

Browse files
committed
[refactor] rewrite Badge, Spinner, Jumbotron & Card components
1 parent 409b099 commit 2dc2013

File tree

11 files changed

+259
-203
lines changed

11 files changed

+259
-203
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "boot-cell",
3-
"version": "2.0.0-beta.3",
3+
"version": "2.0.0-beta.4",
44
"license": "LGPL-3.0",
55
"author": "[email protected]",
66
"description": "Web Components UI library based on WebCell v3, BootStrap v5, BootStrap Icon v1 & FontAwesome v6",

source/Badge.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import classNames from 'classnames';
2+
import { FC, WebCellProps } from 'web-cell';
3+
4+
import { Color } from './type';
5+
6+
export interface BadgeProps extends WebCellProps<HTMLAnchorElement> {
7+
bg?: Color;
8+
text?: Color;
9+
pill?: boolean;
10+
}
11+
12+
export const Badge: FC<BadgeProps> = ({
13+
className,
14+
bg,
15+
text,
16+
pill,
17+
href,
18+
children,
19+
...rest
20+
}) => {
21+
const Class = classNames(
22+
'badge',
23+
bg && `text-bg-${bg}`,
24+
text && `text-${text}`,
25+
pill && `rounded-pill`,
26+
href && 'text-decoration-none',
27+
className
28+
);
29+
30+
return href ? (
31+
<a {...rest} className={Class} href={href}>
32+
{children}
33+
</a>
34+
) : (
35+
<span {...rest} className={Class}>
36+
{children}
37+
</span>
38+
);
39+
};

source/Card.tsx

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import classNames from 'classnames';
2+
import { FC, WebCellProps } from 'web-cell';
3+
4+
import { Image, ImageProps } from './Image';
5+
import { Color, PositionY } from './type';
6+
7+
export interface CardProps extends WebCellProps<HTMLDivElement> {
8+
bg?: Color;
9+
text?: Color | 'white' | 'muted';
10+
border?: Color;
11+
body?: boolean;
12+
}
13+
14+
export const Card: FC<CardProps> = ({
15+
className,
16+
bg,
17+
text,
18+
border,
19+
body,
20+
children,
21+
...props
22+
}) => (
23+
<div
24+
className={classNames(
25+
'card',
26+
bg && `text-bg-${bg}`,
27+
text && `text-${text}`,
28+
border && `border-${border}`,
29+
className
30+
)}
31+
{...props}
32+
>
33+
{body ? <CardBody>{children}</CardBody> : children}
34+
</div>
35+
);
36+
37+
export const CardHeader: FC<WebCellProps<HTMLDivElement>> = ({
38+
className = '',
39+
children,
40+
...props
41+
}) => (
42+
<div className={`card-header ${className}`} {...props}>
43+
{children}
44+
</div>
45+
);
46+
47+
export const CardBody: FC<WebCellProps<HTMLDivElement>> = ({
48+
className = '',
49+
children,
50+
...props
51+
}) => (
52+
<div className={`card-body ${className}`} {...props}>
53+
{children}
54+
</div>
55+
);
56+
57+
export const CardFooter: FC<WebCellProps<HTMLDivElement>> = ({
58+
className = '',
59+
children,
60+
...props
61+
}) => (
62+
<div className={`card-footer ${className}`} {...props}>
63+
{children}
64+
</div>
65+
);
66+
67+
export const CardTitle: FC<WebCellProps<HTMLHeadingElement>> = ({
68+
className = '',
69+
children,
70+
...props
71+
}) => (
72+
<h5 className={`card-title ${className}`} {...props}>
73+
{children}
74+
</h5>
75+
);
76+
77+
export interface CardImgProps extends ImageProps {
78+
variant?: PositionY;
79+
}
80+
81+
export const CardImg: FC<CardImgProps> = ({
82+
className = '',
83+
variant,
84+
...props
85+
}) => (
86+
<Image
87+
className={`card-img${variant ? `-${variant}` : ''} ${className}`}
88+
{...props}
89+
/>
90+
);

source/Jumbotron.tsx

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import classNames from 'classnames';
2+
import { JsxChildren } from 'dom-renderer';
3+
import { FC, WebCellProps } from 'web-cell';
4+
5+
import { BackgroundColor } from './type';
6+
import { Container, ContainerProps } from './Grid';
7+
8+
export interface JumbotronProps
9+
extends Omit<ContainerProps, 'title'>,
10+
Record<'title' | 'description', JsxChildren> {
11+
bg?: BackgroundColor;
12+
rounded?: 0 | 1 | 2 | 3 | 4 | 5;
13+
}
14+
15+
export const Jumbotron: FC<JumbotronProps> = ({
16+
className,
17+
fluid,
18+
bg = 'body-tertiary',
19+
rounded = fluid ? 0 : 3,
20+
title,
21+
description,
22+
children,
23+
...props
24+
}) => {
25+
const content = (
26+
<>
27+
<h1 className="display-4">{title}</h1>
28+
29+
<p className="lead">{description}</p>
30+
31+
{children && (
32+
<>
33+
<hr className="my-4" />
34+
{children}
35+
</>
36+
)}
37+
</>
38+
);
39+
40+
return (
41+
<header
42+
className={classNames(
43+
'py-5',
44+
!fluid && 'px-5',
45+
bg && `bg-${bg}`,
46+
rounded && `rounded-${rounded}`,
47+
className
48+
)}
49+
{...props}
50+
>
51+
{fluid ? <Container fluid={fluid}>{content}</Container> : content}
52+
</header>
53+
);
54+
};

source/Spinner.tsx

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import classNames from 'classnames';
2+
import { FC, WebCellProps } from 'web-cell';
3+
4+
import { Color } from './type';
5+
6+
export interface SpinnerProps extends WebCellProps<HTMLDivElement> {
7+
variant?: Color;
8+
size?: 'sm';
9+
animation?: 'border' | 'grow';
10+
}
11+
12+
export const Spinner: FC<SpinnerProps> = ({
13+
className,
14+
variant,
15+
size,
16+
animation = 'border',
17+
children = 'Loading...',
18+
...props
19+
}) => (
20+
<div
21+
className={classNames(
22+
`spinner-${animation}`,
23+
size && `spinner-${animation}-${size}`,
24+
variant && `text-${variant}`,
25+
className
26+
)}
27+
role="status"
28+
{...props}
29+
>
30+
<span className="visually-hidden">{children}</span>
31+
</div>
32+
);
33+
34+
export interface SpinnerBoxProps extends SpinnerProps {
35+
cover?: boolean;
36+
}
37+
38+
export const SpinnerBox: FC<SpinnerBoxProps> = ({
39+
className = '',
40+
cover,
41+
variant,
42+
size,
43+
animation,
44+
role,
45+
children,
46+
...props
47+
}) => (
48+
<div className={`position-relative ${className}`} {...props}>
49+
{children}
50+
51+
{cover && (
52+
<div className="modal-backdrop show d-flex justify-content-center align-items-center">
53+
<Spinner
54+
{...{ variant, size, animation, role, ariaHidden: 'true' }}
55+
/>
56+
</div>
57+
)}
58+
</div>
59+
);

source/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ export * from './Ratio';
33
export * from './Grid';
44
export * from './Table';
55
export * from './ScrollBoundary';
6+
export * from './Jumbotron';
7+
export * from './Card';
68
export * from './Form';
79
export * from './Button';
10+
export * from './Badge';
11+
export * from './Spinner';
812
export * from './Icon';
913
export * from './Image';
1014
export * from './Tooltip';

source/type.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
type Subtle<T extends string> = `${T}${'' | '-subtle'}`;
22

3-
export type Color =
4-
| 'primary'
5-
| 'secondary'
6-
| 'success'
7-
| 'danger'
8-
| 'warning'
9-
| 'info'
10-
| 'light'
11-
| 'dark';
3+
export enum Status {
4+
primary = 'primary',
5+
secondary = 'secondary',
6+
tertiary = 'tertiary',
7+
success = 'success',
8+
info = 'info',
9+
warning = 'warning',
10+
danger = 'danger'
11+
}
12+
13+
export type Color = Exclude<keyof typeof Status, 'tertiary'> | 'light' | 'dark';
1214

1315
export type BackgroundColor =
1416
| Subtle<Color>
15-
| `body${'' | '-secondary' | '-tertiary'}`
17+
| `body${'' | '-emphasis' | '-secondary' | '-tertiary'}`
1618
| 'black'
1719
| 'white'
1820
| 'transparent';

v1/Content/Jumbotron.tsx

Lines changed: 0 additions & 44 deletions
This file was deleted.

v1/Prompt/Spinner/index.less

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)