Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(components): add TagButton #1504

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wet-turkeys-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@launchpad-ui/components": patch
---

Add `TagButton`
38 changes: 38 additions & 0 deletions packages/components/src/TagButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { ForwardedRef } from 'react';
import type { ButtonProps } from 'react-aria-components';
import type { TagVariants } from './TagGroup';

import { forwardRef } from 'react';
import { composeRenderProps } from 'react-aria-components';

import { Button } from './Button';
import { tag } from './TagGroup';

interface TagButtonProps extends ButtonProps, Omit<TagVariants, 'variant'> {}

const _TagButton = (
{ size = 'medium', ...props }: TagButtonProps,
ref: ForwardedRef<HTMLButtonElement>,
) => {
return (
<Button
{...props}
ref={ref}
variant="default"
size={null}
className={composeRenderProps(props.className, (className, renderProps) =>
tag({ ...renderProps, size, variant: null, className }),
)}
/>
);
};

/**
* A button allows a user to perform an action, with mouse, touch, and keyboard interactions.
*
* https://react-spectrum.adobe.com/react-aria/Button.html
*/
const TagButton = forwardRef(_TagButton);

export { TagButton };
export type { TagButtonProps };
7 changes: 4 additions & 3 deletions packages/components/src/TagGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ const tag = cva(styles.tag, {
},
});

interface TagProps extends AriaTagProps, VariantProps<typeof tag> {}
interface TagVariants extends VariantProps<typeof tag> {}
interface TagProps extends AriaTagProps, TagVariants {}

const _TagGroup = ({ className, ...props }: TagGroupProps, ref: ForwardedRef<HTMLDivElement>) => {
return <AriaTagGroup {...props} ref={ref} className={group({ className })} />;
Expand Down Expand Up @@ -107,5 +108,5 @@ const _Tag = (
*/
const Tag = forwardRef(_Tag);

export { TagGroup, TagList, Tag };
export type { TagGroupProps, TagListProps, TagProps };
export { TagGroup, TagList, Tag, tag };
export type { TagGroupProps, TagListProps, TagProps, TagVariants };
2 changes: 2 additions & 0 deletions packages/components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export type {
TableHeaderProps,
} from './Table';
export type { TabProps, TabsProps, TabListProps, TabPanelProps } from './Tabs';
export type { TagButtonProps } from './TagButton';
export type { TagGroupProps, TagListProps, TagProps } from './TagGroup';
export type { TextProps } from './Text';
export type { TextAreaProps } from './TextArea';
Expand Down Expand Up @@ -147,6 +148,7 @@ export {
TableHeader,
} from './Table';
export { Tab, Tabs, TabList, TabPanel } from './Tabs';
export { TagButton } from './TagButton';
export { TagGroup, TagList, Tag } from './TagGroup';
export { Text } from './Text';
export { TextArea } from './TextArea';
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/styles/TagGroup.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@

.small {
font: var(--lp-text-label-2-medium);
height: var(--lp-size-20);
}

.medium {
font: var(--lp-text-label-1-medium);
height: var(--lp-size-24);
}

.default {
Expand Down
15 changes: 15 additions & 0 deletions packages/components/stories/composition.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
RadioIconButton,
Select,
SelectValue,
TagButton,
Text,
ToastContainer,
ToastQueue,
Expand Down Expand Up @@ -256,3 +257,17 @@ export const DisabledWithTooltip: Story = {
);
},
};

export const TagWithOverlay: Story = {
render: () => {
return (
<TooltipTrigger>
<TagButton>
<Icon name="osmo" size="small" />
TagButton
</TagButton>
<Tooltip placement="right">Message</Tooltip>
</TooltipTrigger>
);
},
};
Loading