-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docs): Interactive playground component (#140)
* playground component initial commit * named params * Checkbox fix * icon btn fix * revert naming * review comments * Rename to preview * Changes * fix: button variant prop * fix: updated styling * fix: overflow issue Co-authored-by: Shibu Lijack <[email protected]> Co-authored-by: Shibu Lijack <[email protected]>
- Loading branch information
1 parent
3cf8a05
commit 3daf9bf
Showing
27 changed files
with
657 additions
and
107 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,21 @@ | ||
// icon tiles | ||
.icon-container { | ||
display: flex; | ||
flex-wrap: wrap; | ||
|
||
.icon { | ||
text-align: center; | ||
padding: 10px 5px 5px; | ||
margin: 5px; | ||
width: 150px; | ||
cursor: pointer; | ||
|
||
&:hover { | ||
background: #dae1e7; | ||
} | ||
|
||
&--text { | ||
padding: 5px 0; | ||
} | ||
} | ||
} |
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,52 @@ | ||
$playground-border-color: #dae1e7; | ||
$padding: 8px; | ||
|
||
.playground-container { | ||
display: flex; | ||
border-bottom: 1px dotted $playground-border-color; | ||
justify-content: space-around; | ||
|
||
&--preview { | ||
display: flex; | ||
align-self: center; | ||
width: 75%; | ||
justify-content: center; | ||
padding: $padding; | ||
} | ||
|
||
&--props { | ||
padding: $padding; | ||
border-left: 1px dotted $playground-border-color; | ||
max-height: 25vh; | ||
width: 50%; | ||
overflow-y: auto; | ||
|
||
.item { | ||
margin: 10px; | ||
|
||
&--label { | ||
display: block; | ||
padding-bottom: $padding; | ||
font-weight: 700; | ||
} | ||
|
||
.ember-text-field { | ||
border: 1px solid $playground-border-color; | ||
padding: $padding; | ||
} | ||
} | ||
} | ||
|
||
&--code { | ||
position: relative; | ||
margin: 8px; | ||
padding: $padding 0; | ||
overflow-x: hidden; | ||
} | ||
|
||
&--code-copy { | ||
position: absolute; | ||
right: 0; | ||
bottom: 0; | ||
} | ||
} |
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
4 changes: 4 additions & 0 deletions
4
packages/@nucleus/tests/dummy/app/components/docs-playground.js
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,4 @@ | ||
import Component from '@ember/component'; | ||
|
||
export default Component.extend({ | ||
}); |
21 changes: 21 additions & 0 deletions
21
packages/@nucleus/tests/dummy/app/components/docs-playground/code.js
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,21 @@ | ||
import Component from '@ember/component'; | ||
import { action, computed, get } from '@ember/object'; | ||
import { highlightCode } from 'ember-cli-addon-docs/utils/compile-markdown'; | ||
import copyToClipboard from '../../utils/copy-to-clipboard'; | ||
|
||
|
||
class Code extends Component { | ||
@computed('code') | ||
get computedCode() { | ||
return highlightCode(get(this, 'code'), 'hbs'); | ||
} | ||
|
||
|
||
@action | ||
copyCode() { | ||
copyToClipboard(get(this, 'code')) | ||
.then(this.flashMessages.success(`Code copied.`)); | ||
} | ||
} | ||
|
||
export default Code; |
5 changes: 5 additions & 0 deletions
5
packages/@nucleus/tests/dummy/app/components/docs-playground/preview.js
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,5 @@ | ||
import Component from '@ember/component'; | ||
|
||
export default Component.extend({ | ||
tagName: '' | ||
}); |
13 changes: 13 additions & 0 deletions
13
packages/@nucleus/tests/dummy/app/components/docs-playground/props.js
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,13 @@ | ||
import Component from '@ember/component'; | ||
import { action } from '@ember/object'; | ||
|
||
class Props extends Component { | ||
@action | ||
handleChange(property, e) { | ||
let value = (property.toggle) ? e.target.checked : e.target.value; | ||
this.onchange(property.name, value, e); | ||
} | ||
|
||
} | ||
|
||
export default Props; |
121 changes: 121 additions & 0 deletions
121
packages/@nucleus/tests/dummy/app/components/nucleus-button/playground.js
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,121 @@ | ||
import Component from '@ember/component'; | ||
import { get, set, action } from "@ember/object"; | ||
import { | ||
registerComputedProperties, | ||
handlePropertyChange, | ||
generateCode | ||
} from '../../utils/playground'; | ||
|
||
import icons from '../../constants/icons'; | ||
|
||
const PROPERTIES = [ | ||
{ | ||
name: 'label', | ||
input: true, | ||
value: 'Click here', | ||
}, | ||
{ | ||
name: 'variant', | ||
select: true, | ||
value: 'primary', | ||
types: [ | ||
'primary', | ||
'secondary', | ||
'danger', | ||
'link', | ||
'text' | ||
] | ||
}, | ||
{ | ||
name: 'size', | ||
select: true, | ||
value: 'none', | ||
types: [ | ||
'none', | ||
'small', | ||
'mini' | ||
] | ||
}, | ||
{ | ||
name: 'block', | ||
toggle: true, | ||
value: false, | ||
}, | ||
{ | ||
name: 'disabled', | ||
toggle: true, | ||
value: false, | ||
}, | ||
{ | ||
name: 'icon', | ||
select: true, | ||
value: 'none', | ||
types: [ | ||
'none', | ||
...icons | ||
] | ||
}, | ||
{ | ||
name: 'iconSize', | ||
select: true, | ||
value: 'none', | ||
types: [ | ||
'none', | ||
'medium', | ||
'small', | ||
'mini' | ||
] | ||
}, | ||
{ | ||
name: 'iconOnly', | ||
toggle: true, | ||
value: false, | ||
} | ||
] | ||
class Playground extends Component { | ||
properties = PROPERTIES; | ||
|
||
code = null; | ||
|
||
init() { | ||
super.init(...arguments); | ||
registerComputedProperties(this, get(this, 'properties')); | ||
this._generateCode(); | ||
} | ||
|
||
@action | ||
onchange(name, value) { | ||
let properties = get(this, 'properties'); | ||
|
||
if (name === 'iconOnly' && !name.value) { | ||
this._handleIconOnly(properties); | ||
} | ||
|
||
handlePropertyChange(properties, name, value); | ||
this._generateCode(); | ||
} | ||
|
||
|
||
_generateCode() { | ||
set(this, 'code', generateCode({ | ||
component:'nucleus-button', | ||
properties: get(this, 'properties'), | ||
multiline: true | ||
})); | ||
} | ||
|
||
_handleIconOnly(properties) { | ||
let changables = ['label', 'variant', 'icon']; | ||
let [ | ||
label, | ||
type, | ||
icon | ||
] = properties.filter(prop => changables.includes(prop.name)); | ||
|
||
set(label, 'value', ''); | ||
set(type, 'value', 'text'); | ||
set(icon, 'value', (icon.value === 'none') ? icon.types[1] : icon.value); | ||
} | ||
} | ||
|
||
export default Playground; |
25 changes: 13 additions & 12 deletions
25
packages/@nucleus/tests/dummy/app/components/nucleus-icon/demo-1.js
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,23 +1,24 @@ | ||
// BEGIN-SNIPPET nucleus-icon.js | ||
import Component from '@ember/component'; | ||
|
||
const ICON_LIST = [ | ||
"nucleus-circle-check", | ||
"nucleus-circle-cross", | ||
"nucleus-circle-help", | ||
"nucleus-circle-info", | ||
"nucleus-circle-minus", | ||
"nucleus-circle-plus", | ||
"nucleus-cross-thin", | ||
"nucleus-cross" | ||
]; | ||
import { inject } from '@ember/service'; | ||
import copyToClipboard from '../../utils/copy-to-clipboard'; | ||
import icons from '../../constants/icons'; | ||
|
||
export default Component.extend({ | ||
flashMessages: inject(), | ||
|
||
icons: null, | ||
|
||
init() { | ||
this._super(...arguments); | ||
this.set('icons', ICON_LIST) | ||
this.set('icons', icons) | ||
}, | ||
|
||
actions: { | ||
copyIcon(icon) { | ||
copyToClipboard(icon) | ||
.then(this.flashMessages.success(`Copied '${icon}' to clipboard`)); | ||
} | ||
} | ||
}); | ||
// END-SNIPPET |
67 changes: 67 additions & 0 deletions
67
packages/@nucleus/tests/dummy/app/components/nucleus-icon/playground.js
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,67 @@ | ||
import Component from '@ember/component'; | ||
import { get, set, action } from "@ember/object"; | ||
import { | ||
registerComputedProperties, | ||
handlePropertyChange, | ||
generateCode | ||
} from '../../utils/playground'; | ||
import icons from '../../constants/icons'; | ||
|
||
|
||
const PROPERTIES = [ | ||
{ | ||
name: 'name', | ||
select: true, | ||
value: 'nucleus-circle-check', | ||
types: icons | ||
}, | ||
{ | ||
name: 'size', | ||
select: true, | ||
value: 'large', | ||
types: [ | ||
'small', | ||
'medium', | ||
'large' | ||
] | ||
}, | ||
{ | ||
name: 'variant', | ||
select: true, | ||
value: 'none', | ||
types: [ | ||
'none', | ||
'danger', | ||
'success' | ||
] | ||
} | ||
] | ||
|
||
class Playground extends Component { | ||
properties = PROPERTIES; | ||
|
||
code = null; | ||
|
||
init() { | ||
super.init(...arguments); | ||
registerComputedProperties(this, get(this, 'properties')); | ||
this._generateCode(); | ||
} | ||
|
||
@action | ||
onchange(name, value) { | ||
handlePropertyChange(get(this, 'properties'), name, value); | ||
this._generateCode(); | ||
} | ||
|
||
|
||
_generateCode() { | ||
set(this, 'code', generateCode({ | ||
component: 'nucleus-icon', | ||
properties: get(this, 'properties') | ||
})); | ||
} | ||
} | ||
|
||
export default Playground; | ||
|
Oops, something went wrong.