-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add Chip #11
Merged
Add Chip #11
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
38ec8cf
feat(react-components): added chip component
MarikTar b2926ae
chore(react-components): deleted unused style
MarikTar 4a46736
chore(react-components): fixed lint error
MarikTar 7ba0cd7
chore(react-components): made requested changes
MarikTar f61d38a
chore(react-components): made requested changes
MarikTar 39ab52f
Merge branch 'main' of github.com:PeculiarVentures/peculiar-ui into a…
donskov cf59b53
Merge branch 'add-chip' of github.com:PeculiarVentures/peculiar-ui in…
donskov 22259c3
chore(react-components): move icons to separate folder, update Chip s…
donskov 7b930cb
chore(react-components): add Chip to main export
donskov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,20 @@ | ||
import * as React from 'react'; | ||
import { Chip } from './index'; | ||
|
||
export const Playground = (args: any) => ( | ||
<Chip | ||
{...args} | ||
/> | ||
); | ||
|
||
Playground.args = { | ||
children: 'Hello', | ||
}; | ||
|
||
export default { | ||
title: 'Components/Chip', | ||
component: Chip, | ||
argTypes: { | ||
children: { control: 'text' }, | ||
}, | ||
}; |
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,149 @@ | ||
import * as React from 'react'; | ||
import { css, cx } from '../styles'; | ||
import { Typography } from '../Typography'; | ||
import { CheckmarkIcon } from '../icons'; | ||
|
||
type BaseProps = { | ||
/** | ||
* The content of the component. | ||
*/ | ||
children: React.ReactNode; | ||
/** | ||
* If `true`, the chip will be disabled. | ||
*/ | ||
disabled?: boolean; | ||
/** | ||
* The variant to use. | ||
*/ | ||
variant?: ('choice' | 'filter'); | ||
/** | ||
* If `true`, the chip will be selected. | ||
*/ | ||
selected: boolean; | ||
/** | ||
* The className of the component. | ||
*/ | ||
className?: string; | ||
dataTestId?: string; | ||
}; | ||
|
||
type ChipProps = BaseProps & React.ButtonHTMLAttributes<HTMLButtonElement>; | ||
|
||
const stylesBase = () => css({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
label: 'Chip', | ||
display: 'inline-flex', | ||
alignItems: 'center', | ||
fontFamily: 'inherit', | ||
outline: 'none', | ||
boxSizing: 'border-box', | ||
borderStyle: 'solid', | ||
borderWidth: '1px', | ||
borderColor: 'var(--pv-color-gray-6)', | ||
borderRadius: '15px', | ||
padding: '0 10px', | ||
height: '30px', | ||
backgroundColor: 'transparent', | ||
color: 'var(--pv-color-gray-9)', | ||
transition: 'background-color 200ms, color 200ms, border-color 200ms', | ||
margin: '0 5px', | ||
'&:disabled': { | ||
cursor: 'not-allowed', | ||
color: 'var(--pv-color-gray-7)', | ||
borderColor: 'var(--pv-color-gray-4)', | ||
backgroundColor: 'transparent', | ||
}, | ||
}); | ||
|
||
const stylesEffects = () => css({ | ||
label: 'effects', | ||
cursor: 'pointer', | ||
'&:not(:disabled)': { | ||
'&:hover': { | ||
backgroundColor: 'var(--pv-color-gray-3)', | ||
color: 'var(--pv-color-gray-9)', | ||
}, | ||
'&:focus': { | ||
backgroundColor: 'var(--pv-color-gray-5)', | ||
color: 'var(--pv-color-black)', | ||
borderColor: 'var(--pv-color-gray-9)', | ||
}, | ||
'&:active': { | ||
backgroundColor: 'var(--pv-color-gray-4)', | ||
color: 'var(--pv-color-gray-9)', | ||
borderColor: 'var(--pv-color-gray-9)', | ||
}, | ||
}, | ||
}); | ||
|
||
const stylesChoiceSelected = () => css({ | ||
label: 'choice-selected', | ||
backgroundColor: 'var(--pv-color-secondary-tint-5)', | ||
color: 'var(--pv-color-secondary)', | ||
borderColor: 'var(--pv-color-secondary-tint-3)', | ||
}); | ||
|
||
const stylesFilterSelected = () => css({ | ||
label: 'filter-selected', | ||
backgroundColor: 'var(--pv-color-gray-4)', | ||
color: 'var(--pv-color-black)', | ||
borderColor: 'var(--pv-color-gray-7)', | ||
}); | ||
|
||
const stylesIcon = () => css({ | ||
label: 'Chip-icon', | ||
marginRight: '10px', | ||
display: 'flex', | ||
alignItems: 'center', | ||
}); | ||
|
||
export const Chip = React.forwardRef<HTMLButtonElement, ChipProps>((props, ref) => { | ||
donskov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const { | ||
children, | ||
className, | ||
dataTestId, | ||
disabled, | ||
variant, | ||
selected, | ||
tabIndex, | ||
...other | ||
} = props; | ||
const isChoice = variant === 'choice'; | ||
|
||
const Icon = selected && !isChoice && ( | ||
<div className={cx(stylesIcon())}> | ||
<CheckmarkIcon /> | ||
</div> | ||
); | ||
|
||
return ( | ||
<button | ||
{...other} | ||
disabled={disabled} | ||
ref={ref} | ||
type="button" | ||
className={cx({ | ||
[stylesBase()]: true, | ||
[stylesChoiceSelected()]: selected && isChoice, | ||
[stylesFilterSelected()]: selected && !isChoice, | ||
[stylesEffects()]: !selected || !isChoice, | ||
[className]: !!className, | ||
})} | ||
tabIndex={selected && isChoice ? -1 : tabIndex} | ||
data-testid={dataTestId} | ||
> | ||
{Icon} | ||
<Typography | ||
variant="b3" | ||
> | ||
{children} | ||
</Typography> | ||
</button> | ||
); | ||
}); | ||
|
||
Chip.displayName = 'Chip'; | ||
|
||
Chip.defaultProps = { | ||
disabled: false, | ||
variant: 'choice', | ||
}; |
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 @@ | ||
export { Chip } from './chip'; |
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,18 @@ | ||
import React from 'react'; | ||
|
||
type IconProps = React.HTMLAttributes<HTMLOrSVGElement>; | ||
|
||
export const CheckmarkIcon: React.FC<IconProps> = (props) => ( | ||
<svg | ||
{...props} | ||
xmlns="http://www.w3.org/2000/svg" | ||
fill="none" | ||
viewBox="0 0 20 20" | ||
width="20px" | ||
> | ||
<path | ||
fill="currentColor" | ||
d="M3.6 9.7l4.9 4.6c.4.4 1 .4 1.4 0l5.9-7v-.6l-.4-.3a.4.4 0 00-.6 0L9.1 13 4.5 8.8a.4.4 0 00-.6 0l-.3.3c-.2.2-.2.5 0 .6z" | ||
/> | ||
</svg> | ||
); |
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 @@ | ||
export { CheckmarkIcon } from './checkmark_icon'; |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now
Chip
component can use props fromHTMLButtonElement
, but you forgot to add...other
props to your root element.