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: Tag component #12

Merged
merged 5 commits into from
Dec 17, 2020
Merged

feat: Tag component #12

merged 5 commits into from
Dec 17, 2020

Conversation

anuraghazra
Copy link
Contributor

@anuraghazra anuraghazra commented Dec 16, 2020

Tag Component

References:
Ant Design : https://ant.design/components/tag
Vercel: https://vercel.com/design/tag
UI Patterns: http://ui-patterns.com/patterns/Tag

Although Tag component looks same as our Button component with icons on both sides and content. Use cases and the API can be a bit different since Tag is a closable/removable item.

When to use:

  • Organizing/Categorizing based on tags
  • Adding filters with removable tags

Props

  • closable - boolean | default - false
  • prefix - ReactNode | default - null
  • suffix - ReactNode | default - <CloseIcon />
  • onClose - (id) => void | callback to fire on close icon is clicked

By default Tag component will have x close icon in the suffix if the closable prop is true.

API

<Tag prefix={<UserIcon />} closable onClose={() => alert(1)}>
  Tag
</Tag>

Change suffix icon

<Tag suffix={<UserIcon />} closable onClose={() => alert(1)}>
  Tag
</Tag>

TagGroup

Reference: https://vercel.com/design/tag

We can also add a TagGroup component to handle the keyboard logic for the multiple tags
Ideally TagGroup will be a composite which would allows users to navigate the tags icons with ArrowLeft/Right
Note: The state logic for removing/adding the tags will be handled by the user not us.

Props

  • allowArrowNavigation - boolean | if true will enable arrow navigation for the close icons
const [tags, setTags] = useState(['One', 'Two', 'Three'])
return (
  <TagGroup>
    {tags.map(tag => (
      <Tag
        id={tag}
        key={tag}
        onClose={id => setTags(tags.filter(t => t !== id))}
  >    
        {tag}
      </Tag>
    ))}
  </TagGroup>
)

@vercel
Copy link

vercel bot commented Dec 16, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/timelessco/renderlesskit-react-tailwind/j8qeyfn87
✅ Preview: https://renderlesskit-react-tailwind-git-tag-component.timelessco.vercel.app

src/Tag/Tag.tsx Outdated Show resolved Hide resolved
@navin-moorthy
Copy link
Contributor

Allow styling default close icon 🤔

@anuraghazra
Copy link
Contributor Author

Allow styling default close icon 🤔

If they want to style the default close icon they can provide their own close icon that's the idea here.

  • reduces props
  • simpler api
  • more flexiblity

Copy link
Contributor

@navin-moorthy navin-moorthy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉

@anuraghazra anuraghazra merged commit 0d681f3 into main Dec 17, 2020
@anuraghazra anuraghazra deleted the tag-component branch December 17, 2020 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants