-
Notifications
You must be signed in to change notification settings - Fork 4
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
feature(components): add chip component #11
Open
archzaiko
wants to merge
2
commits into
redesign
Choose a base branch
from
redesign-sdk-chip
base: redesign
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ | ||
$images-path: "../images/components"; |
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,110 @@ | ||
.chip { | ||
display: inline-block; | ||
padding: 4px 8px; | ||
border: 1px solid #E5E5E5; | ||
border-radius: 16px; | ||
|
||
font-family: "Roboto-Regular"; | ||
font-size: 14px; | ||
line-height: 16px; | ||
color: #8B8B8F; | ||
|
||
cursor: pointer; | ||
|
||
&:hover { | ||
box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.25); | ||
color: #010101; | ||
} | ||
} | ||
|
||
.chip__content { | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
||
.chip__buttons { | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
||
.chip__icon { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
width: 16px; | ||
height: 16px; | ||
|
||
&:before { | ||
display: block; | ||
content: ''; | ||
width: 8px; | ||
height: 8px; | ||
background-position: center; | ||
background-repeat: no-repeat; | ||
background-size: contain; | ||
} | ||
|
||
&.chip__icon_name_drag { | ||
width: 2px; | ||
margin-right: 4px; | ||
|
||
&:before { | ||
width: 2px; | ||
background-image: url('#{$images-path}/chip/icon-chip-ellipsis-vertical.svg'); | ||
} | ||
} | ||
|
||
&.chip__icon_name_active:before { | ||
width: 12px; | ||
background-image: url('#{$images-path}/chip/icon-chip-active.svg'); | ||
} | ||
} | ||
|
||
.chip__button { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
width: 16px; | ||
height: 16px; | ||
|
||
&:before { | ||
display: block; | ||
content: ''; | ||
width: 12px; | ||
height: 12px; | ||
background-position: center; | ||
background-repeat: no-repeat; | ||
background-size: contain; | ||
} | ||
|
||
&.chip__button_action_delete:before { | ||
width: 8px; | ||
height: 8px; | ||
background-image: url('#{$images-path}/chip/icon-chip-delete.svg'); | ||
} | ||
} | ||
|
||
.chip { | ||
&:not(.chip_state_active) { | ||
.chip__icon_name_active { | ||
display: none; | ||
} | ||
} | ||
|
||
&.chip_state_active { | ||
.chip__button_action_delete { | ||
display: none; | ||
} | ||
} | ||
|
||
&:not(:hover) { | ||
.chip__icon_name_drag { | ||
visibility: hidden; | ||
} | ||
} | ||
} | ||
|
||
.chip__text { | ||
margin-right: 6px; | ||
user-select: none; | ||
} |
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,86 @@ | ||
import * as React from 'react'; | ||
|
||
interface IChip { | ||
value: any; | ||
text: string; | ||
active?: boolean; | ||
maxLength?: number; | ||
onChange?: ( state: IChipState ) => any; | ||
onDelete?: ( state: IChipState ) => any; | ||
} | ||
|
||
interface IChipState { | ||
text: string; | ||
value: any; | ||
active: boolean; | ||
} | ||
|
||
/** | ||
* Chip component | ||
* @param props { IChip } - component properties | ||
* @returns | ||
*/ | ||
export function Chip (props: IChip) { | ||
const { | ||
value = null, | ||
text = '', | ||
maxLength = 15, | ||
active = false, | ||
onChange = null, | ||
onDelete = null | ||
} = props; | ||
|
||
const chipClassList = ['chip']; | ||
|
||
// add a class for applying CSS styles when the chip is active | ||
if (active) { | ||
chipClassList.push('chip_state_active'); | ||
} | ||
|
||
// trim the "text" if its length is greater than "maxLength" | ||
const chipText = text.length > maxLength ? text.slice(0, maxLength) + '..' : text; | ||
|
||
// call the "onChange" function when the chip is clicked | ||
// skip clicks on chip buttons | ||
const handleChange = (event: React.MouseEvent<HTMLElement>) => { | ||
if ( !isButtonElement(event.target as HTMLElement) ) { | ||
onChange && onChange({ text, value, active }); | ||
} | ||
}; | ||
|
||
// call the "onDelete" function when the "delete" button is clicked | ||
const handleDelete = () => { | ||
onDelete && onDelete({ text, value, active }); | ||
}; | ||
|
||
return ( | ||
<div | ||
className={ chipClassList.join(' ') } | ||
title={ text } | ||
onClick={ (event) => { | ||
handleChange(event); | ||
} } | ||
> | ||
<div className="chip__content"> | ||
<span className="chip__icon chip__icon_name_drag"></span> | ||
<div className="chip__text">{ chipText }</div> | ||
<span className="chip__icon chip__icon_name_active"></span> | ||
<span | ||
className="chip__button chip__button_action_delete" | ||
onClick={ (event) => { | ||
handleDelete(); | ||
} } | ||
></span> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
/** | ||
* Returns true, if the element is [inside] the chip button element | ||
* @param element { HTMLElement } - an | ||
* @returns boolean; | ||
*/ | ||
function isButtonElement (element: HTMLElement): boolean { | ||
return element && !!element.closest('.chip__button'); | ||
} |
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,2 @@ | ||
@import "./variables"; | ||
@import "./chip/chip.component"; |
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.
let's use rem instead. Also, it will be nice to store these values as a common variables. (for future possible design changes)