mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2025-07-27 20:22:33 +08:00
[ui][badge] allow icon addon
This commit is contained in:
@ -1,4 +1,11 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import {
|
||||||
|
CheckCircleIcon,
|
||||||
|
ExclamationCircleIcon,
|
||||||
|
ExclamationTriangleIcon,
|
||||||
|
InformationCircleIcon,
|
||||||
|
StarIcon,
|
||||||
|
} from '@heroicons/react/20/solid';
|
||||||
import type { ComponentMeta } from '@storybook/react';
|
import type { ComponentMeta } from '@storybook/react';
|
||||||
import type { BadgeVariant } from '@tih/ui';
|
import type { BadgeVariant } from '@tih/ui';
|
||||||
import { Badge } from '@tih/ui';
|
import { Badge } from '@tih/ui';
|
||||||
@ -40,3 +47,23 @@ export function Variants() {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function Icon() {
|
||||||
|
return (
|
||||||
|
<div className="space-x-4">
|
||||||
|
<Badge endAddOn={StarIcon} label="Primary" variant="primary" />
|
||||||
|
<Badge endAddOn={CheckCircleIcon} label="Success" variant="success" />
|
||||||
|
<Badge
|
||||||
|
endAddOn={InformationCircleIcon}
|
||||||
|
label="Information"
|
||||||
|
variant="info"
|
||||||
|
/>
|
||||||
|
<Badge
|
||||||
|
endAddOn={ExclamationTriangleIcon}
|
||||||
|
label="Warning"
|
||||||
|
variant="warning"
|
||||||
|
/>
|
||||||
|
<Badge endAddOn={ExclamationCircleIcon} label="Danger" variant="danger" />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
@ -8,6 +8,7 @@ export type BadgeVariant =
|
|||||||
| 'warning';
|
| 'warning';
|
||||||
|
|
||||||
type Props = Readonly<{
|
type Props = Readonly<{
|
||||||
|
endAddOn?: React.ComponentType<React.ComponentProps<'svg'>>;
|
||||||
label: string;
|
label: string;
|
||||||
variant: BadgeVariant;
|
variant: BadgeVariant;
|
||||||
}>;
|
}>;
|
||||||
@ -41,7 +42,7 @@ const classes: Record<
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function Badge({ label, variant }: Props) {
|
export default function Badge({ endAddOn: EndAddOn, label, variant }: Props) {
|
||||||
const { backgroundClass, textClass } = classes[variant];
|
const { backgroundClass, textClass } = classes[variant];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -51,7 +52,8 @@ export default function Badge({ label, variant }: Props) {
|
|||||||
backgroundClass,
|
backgroundClass,
|
||||||
textClass,
|
textClass,
|
||||||
)}>
|
)}>
|
||||||
{label}
|
<span>{label}</span>
|
||||||
|
{EndAddOn && <EndAddOn aria-hidden="true" className="ml-1 h-4 w-4" />}
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user