Skip to content

Commit

Permalink
feat(ui): add badge component
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardoperra committed Sep 4, 2022
1 parent 907ca61 commit 5f2b70b
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/unlucky-zoos-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@codeimage/ui': minor
---

feat(ui): add Badge component
9 changes: 1 addition & 8 deletions apps/codeimage/src/components/UserBadge/UserBadge.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@ import {themeVars} from '@codeimage/ui';
import {style} from '@vanilla-extract/css';

export const badge = style({
width: '36px',
height: '36px',
fontSize: '15px',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
borderRadius: themeVars.borderRadius.lg,
backgroundColor: themeVars.backgroundColor.indigo['500'],
backgroundColor: themeVars.backgroundColor.green['600'],
color: themeVars.backgroundColor.white,
});
8 changes: 5 additions & 3 deletions apps/codeimage/src/components/UserBadge/UserBadge.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {getAuthState} from '@codeimage/store/auth/auth';
import {Button} from '@codeimage/ui';
import {Badge, Button} from '@codeimage/ui';
import {Show} from 'solid-js';
import * as styles from './UserBadge.css';
import {badge} from './UserBadge.css';

export function UserBadge() {
const {loggedIn, signInWithGithub, user} = getAuthState();
Expand All @@ -28,7 +28,9 @@ export function UserBadge() {
}
when={loggedIn()}
>
<div class={styles.badge}>{initials()}</div>
<Badge theme={badge} size={'md'}>
{initials()}
</Badge>
</Show>
);
}
49 changes: 49 additions & 0 deletions packages/ui/src/lib/primitives/Badge/Badge.css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {recipe, RecipeVariants} from '@vanilla-extract/recipes';
import {themeVars} from '../../theme';
import * as textStyles from '../Text/Text.css';
import {fontSize} from '../Text/Text.css';

export const badge = recipe({
base: {
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
borderRadius: themeVars.borderRadius.lg,
},
variants: {
variant: {
rounded: {
borderRadius: '50%',
},
square: {
borderRadius: themeVars.borderRadius.lg,
},
},
size: {
md: [
textStyles.fontSize.base,
{
width: '36px',
height: '36px',
fontSize: fontSize.base,
},
],
sm: [
textStyles.fontSize.sm,
{
width: '28px',
height: '28px',
},
],
xs: [
textStyles.fontSize.xs,
{
width: '24px',
height: '24px',
},
],
},
},
});

export type BadgeVariants = RecipeVariants<typeof badge>;
22 changes: 22 additions & 0 deletions packages/ui/src/lib/primitives/Badge/Badge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import clsx from 'clsx';
import {ParentProps} from 'solid-js';
import {styled} from '../../utils';
import * as styles from './Badge.css';

// eslint-disable-next-line @typescript-eslint/ban-types
export type BadgeProps = styles.BadgeVariants & {
theme: string;
};

export function Badge(props: ParentProps<BadgeProps>) {
const classes = () =>
clsx(
styles.badge({
size: props.size,
variant: props.variant,
}),
props.theme,
);

return <styled.div class={classes()}>{props.children}</styled.div>;
}
1 change: 1 addition & 0 deletions packages/ui/src/lib/primitives/Badge/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Badge';
2 changes: 2 additions & 0 deletions packages/ui/src/lib/primitives/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,5 @@ export {Popover} from './Popover';
export {MenuButton, MenuItem, MenuPopup, DropdownMenuV2} from './Menu';

export {RadioField, RadioGroupField} from './Radio';

export {Badge, type BadgeProps} from './Badge';

0 comments on commit 5f2b70b

Please sign in to comment.