-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
13b79a4
commit 6b99e3b
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react'; | ||
import Chip from './Chip'; | ||
|
||
const App: React.FC = () => { | ||
const handleDelete = () => { | ||
// Handle chip deletion logic | ||
}; | ||
|
||
return ( | ||
<div> | ||
<Chip label="Tag 1" onDelete={handleDelete} /> | ||
<Chip label="Tag 2" /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default App; | ||
|
||
|
||
/* | ||
The first chip has a label "Tag 1" and is associated with the handleDelete function. The second chip has a label "Tag 2" and doesn't have a delete functionality. | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from 'react'; | ||
import { Story, Meta } from '@storybook/react'; | ||
import Chip, { ChipProps } from './Chip'; | ||
|
||
export default { | ||
title: 'Components/Chip', | ||
component: Chip, | ||
} as Meta; | ||
|
||
const Template: Story<ChipProps> = (args) => <Chip {...args} />; | ||
|
||
export const Default = Template.bind({}); | ||
Default.args = { | ||
label: 'Tag 1', | ||
}; | ||
|
||
export const WithDeleteButton = Template.bind({}); | ||
WithDeleteButton.args = { | ||
label: 'Tag 2', | ||
onDelete: () => { | ||
// Handle chip deletion logic | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react'; | ||
import './Chip.css'; | ||
|
||
interface ChipProps { | ||
label: string; | ||
onDelete?: () => void; | ||
} | ||
|
||
const Chip: React.FC<ChipProps> = ({ label, onDelete }) => { | ||
return ( | ||
<div className="chip"> | ||
<span className="chip-label">{label}</span> | ||
{onDelete && ( | ||
<button className="chip-delete" onClick={onDelete}> | ||
× | ||
</button> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Chip; | ||
|
||
/* | ||
label: Represents the text content of the chip. | ||
onDelete (optional): Callback function triggered when the delete button is clicked. | ||
*/ |