Skip to content

Commit

Permalink
feat(odyssey-react-mui): add icon support to Tag
Browse files Browse the repository at this point in the history
  • Loading branch information
edburyenegren-okta committed Jun 6, 2023
1 parent 6810a9c commit 6d1adc4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/odyssey-react-mui/src/Tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,28 @@
*/

import { Chip, ChipProps } from "@mui/material";
import { memo, useContext } from "react";
import { memo, ReactElement, useContext } from "react";
import { TagListContext } from "./TagListContext";
import { Icon } from "./Icon";

export type TagProps = {
icon?: ReactElement<typeof Icon>;
isDisabled?: boolean;
label: string;
onClick?: ChipProps["onClick"];
onRemove?: ChipProps["onDelete"];
};

const Tag = ({ isDisabled, label, onClick, onRemove }: TagProps) => {
const Tag = ({ icon, isDisabled, label, onClick, onRemove }: TagProps) => {
const { chipElementType } = useContext(TagListContext);

return (
<Chip
label={label}
clickable={onClick ? true : false}
component={chipElementType}
disabled={isDisabled}
icon={icon}
label={label}
onClick={onClick}
onDelete={onRemove}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ TagList UI is simple. It consists of typography and spacing within a neutral con
<Story of={Stories.Removable} />
</Canvas>

### Tags with Icons

<Canvas>
<Story of={Stories.Icon} />
</Canvas>

### Disabled Tags

<Canvas>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import { Meta, StoryObj } from "@storybook/react";
import { Tag, TagList, TagProps } from "@okta/odyssey-react-mui";
import { MuiThemeDecorator } from "../../../../.storybook/components";
import { UserGroupIcon } from "@okta/odyssey-react-mui";

const storybookMeta: Meta<TagProps> = {
title: "MUI Components/Tag",
Expand All @@ -24,6 +25,9 @@ const storybookMeta: Meta<TagProps> = {
label: {
control: "text",
},
icon: {
control: "text",
},
isDisabled: {
control: "boolean",
},
Expand Down Expand Up @@ -65,6 +69,13 @@ export const List: StoryObj<TagProps> = {
},
};

export const Icon: StoryObj<TagProps> = {
args: {
label: "Crew",
icon: <UserGroupIcon />,
},
};

export const Clickable: StoryObj<TagProps> = {
args: {
label: "Starship",
Expand Down

0 comments on commit 6d1adc4

Please sign in to comment.