-
Notifications
You must be signed in to change notification settings - Fork 13
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
Adam Raider
committed
Jun 20, 2019
1 parent
d07ecea
commit 2baf420
Showing
8 changed files
with
148 additions
and
1 deletion.
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,12 @@ | ||
--- | ||
label: Component | ||
title: Chip | ||
--- | ||
|
||
<page-intro>Filter chips use tags or descriptive words to filter content. Filter chips clearly delineate and display options in a compact area.</page-intro> | ||
|
||
<component | ||
component="chip" | ||
variation="chip" | ||
> | ||
</component> |
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 @@ | ||
<div class="ray-chip">Neighborhoods</div> |
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,42 @@ | ||
@import '../../global/variables'; | ||
|
||
$ray-chip-border-width: 1px; | ||
$ray-chip-height: $ray-spacing-xs * 2 + 1rem; | ||
|
||
.#{$ray-class-prefix}chip { | ||
@include no-select; | ||
border: $ray-chip-border-width solid $ray-color-blue-50; | ||
background-color: $ray-color-white; | ||
padding: $ray-spacing-xs $ray-spacing-md; | ||
border-radius: $ray-chip-height; | ||
color: $ray-color-blue-50; | ||
display: inline-block; | ||
cursor: pointer; | ||
|
||
&:not(:last-child) { | ||
margin-right: $ray-spacing-xs; | ||
} | ||
|
||
&:hover { | ||
background-color: $ray-color-blue-10; | ||
color: $ray-color-blue-50; | ||
} | ||
|
||
&:focus { | ||
box-shadow: $ray-box-shadow-focus-state; | ||
} | ||
|
||
&:active { | ||
background-color: $ray-color-blue-20; | ||
} | ||
} | ||
|
||
.#{$ray-class-prefix}chip--active { | ||
background-color: $ray-color-blue-50; | ||
color: $ray-color-white; | ||
|
||
&:hover { | ||
background-color: $ray-color-blue-50; | ||
color: $ray-color-white; | ||
} | ||
} |
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,68 @@ | ||
class Chip { | ||
static instances = new WeakMap(); | ||
|
||
static get cssClasses() { | ||
return {}; | ||
} | ||
|
||
static get strings() { | ||
return { | ||
INIT_SELECTOR: '.ray-chip' | ||
}; | ||
} | ||
|
||
static create(element, options) { | ||
return this.instances.get(element) || new this(element, options); | ||
} | ||
|
||
static createAll(target = document, _options = { active: false }) { | ||
// Finds all instances of select on the document or within a given element and instantiates them. | ||
const options = { | ||
initSelector: this.strings.INIT_SELECTOR, | ||
..._options | ||
}; | ||
|
||
const chips = Array.from(target.querySelectorAll(options.initSelector)); | ||
chips.forEach(select => this.create(select, options)); | ||
} | ||
|
||
constructor(root, options) { | ||
this._root = root; | ||
|
||
this.constructor.instances.set(this._root, this); | ||
|
||
this.state = { | ||
active: options.active | ||
}; | ||
|
||
this._bindEventListeners(); | ||
this.assignClasses(); | ||
} | ||
|
||
_bindEventListeners() { | ||
this._root.addEventListener('mousedown', this.onMousedown); | ||
} | ||
|
||
assignClasses() { | ||
if (this.state.active) { | ||
this._root.classList.add('ray-chip--active'); | ||
} else { | ||
this._root.classList.remove('ray-chip--active'); | ||
} | ||
} | ||
|
||
onMousedown = () => { | ||
this.state.active = !this.state.active; | ||
this.assignClasses(); | ||
}; | ||
|
||
destroy() { | ||
// Implement this method to release any resources / deregister any listeners they have | ||
// attached. An example of this might be deregistering a resize event from the window object. | ||
this._root.removeEventListener('mousedown', this.onMousedown); | ||
|
||
this.constructor.instances.delete(this._root); | ||
} | ||
} | ||
|
||
export default 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import Select from './select'; | ||
import { TextField, TextArea } from './text-field'; | ||
import Chip from './chip'; | ||
|
||
export { Select, TextField, TextArea }; | ||
export { Select, TextField, TextArea, 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
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,19 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@storybook/react'; | ||
|
||
import Chip from '../src/components/chip'; | ||
|
||
function initChip() { | ||
Chip.createAll(); | ||
} | ||
|
||
/* eslint-disable no-script-url */ | ||
storiesOf('Chip', module).add('default', () => { | ||
setTimeout(initChip); | ||
return ( | ||
<> | ||
<div className="ray-chip">Neighborhoods</div> | ||
<div className="ray-chip ray-chip--active">Offices</div> | ||
</> | ||
); | ||
}); |
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 |
---|---|---|
|
@@ -46,6 +46,9 @@ | |
"card": { | ||
"title": "Card" | ||
}, | ||
"chip": { | ||
"title": "Chip" | ||
}, | ||
"image": { | ||
"title": "Image" | ||
}, | ||
|