-
Notifications
You must be signed in to change notification settings - Fork 11
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
feat(docs): Interactive playground component #140
Merged
Merged
Changes from 5 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
cd1ecdd
playground component initial commit
prakash-chokalingam 39c6c4e
named params
prakash-chokalingam 0448692
Checkbox fix
prakash-chokalingam d473625
icon btn fix
prakash-chokalingam 4f41ed0
revert naming
prakash-chokalingam 8be3c9e
review comments
prakash-chokalingam 39ccab8
Rename to preview
prakash-chokalingam da75c31
Merge branch 'master' into playground
prakash-chokalingam 2d6d1d8
Changes
prakash-chokalingam d3d26e5
Merge branch 'master' into playground
prakash-chokalingam bdb7a48
Merge branch 'master' into playground
shibulijack-fd 2630a9b
fix: button variant prop
025d6a0
fix: updated styling
e25f3fa
fix: overflow issue
31617c4
Merge branch 'master' into playground
shibulijack-fd 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,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,45 @@ | ||
$playground-border-color: #dae1e7; | ||
|
||
.playground-container { | ||
display: flex; | ||
border-bottom: 1px dotted $playground-border-color; | ||
padding: 10px; | ||
justify-content: space-around; | ||
|
||
&--component { | ||
align-self: center; | ||
width: 50%; | ||
text-align: center; | ||
padding-right: 10px; | ||
} | ||
|
||
&--props { | ||
padding-left: 10px; | ||
border-left: 1px dotted $playground-border-color; | ||
max-height: 25vh; | ||
width: 50%; | ||
overflow-y: auto; | ||
|
||
.item { | ||
margin: 10px; | ||
|
||
&--label { | ||
display: block; | ||
padding-bottom: 5px; | ||
font-weight: 700; | ||
} | ||
} | ||
} | ||
|
||
&--code { | ||
position: relative; | ||
padding: 20px; | ||
} | ||
|
||
&--code-copy { | ||
position: absolute; | ||
right: 0; | ||
bottom: -1px; | ||
padding: 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
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'; | ||
|
||
const PROPERTIES = [ | ||
{ | ||
name: 'label', | ||
input: true, | ||
value: 'Click here', | ||
}, | ||
{ | ||
name: 'type', | ||
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', | ||
'nucleus-circle-check', | ||
'nucleus-cross' | ||
] | ||
}, | ||
{ | ||
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) { | ||
let changables = ['label', 'type', '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); | ||
shibulijack-fd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
handlePropertyChange(properties, name, value); | ||
this._generateCode(); | ||
} | ||
|
||
|
||
_generateCode() { | ||
let attributes = get(this, 'properties').map((prop) => { | ||
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. Is it possible to move this mapping part into util as well? Seems to be duplicated. |
||
return { | ||
name: prop.name, | ||
value: prop.value, | ||
} | ||
}); | ||
|
||
set(this, 'code', generateCode({ | ||
component:'nucleus-button', | ||
attributes, | ||
multiline: true | ||
})); | ||
} | ||
} | ||
|
||
export default Playground; |
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
73 changes: 73 additions & 0 deletions
73
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,73 @@ | ||
import Component from '@ember/component'; | ||
import { get, set, action } from "@ember/object"; | ||
import { | ||
registerComputedProperties, | ||
handlePropertyChange, | ||
generateCode | ||
} from '../../utils/playground'; | ||
|
||
const PROPERTIES = [ | ||
{ | ||
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() { | ||
let props = get(this, 'properties').map((prop) => { | ||
return { | ||
name: prop.name, | ||
value: prop.value, | ||
} | ||
}); | ||
|
||
let staticProps = [ | ||
{ | ||
name: 'name', | ||
value: 'nucleus-circle-help' | ||
} | ||
]; | ||
|
||
set(this, 'code', generateCode({ | ||
component: 'nucleus-icon', | ||
attributes: [...staticProps, ...props] | ||
})); | ||
} | ||
} | ||
|
||
export default Playground; | ||
|
68 changes: 68 additions & 0 deletions
68
packages/@nucleus/tests/dummy/app/components/nucleus-inline-banner/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,68 @@ | ||
import Component from '@ember/component'; | ||
import { get, set, action } from "@ember/object"; | ||
import { | ||
registerComputedProperties, | ||
handlePropertyChange, | ||
generateCode | ||
} from '../../utils/playground'; | ||
|
||
const PROPERTIES = [ | ||
{ | ||
name: 'type', | ||
select: true, | ||
value: 'warning', | ||
types: [ | ||
'warning', | ||
'danger', | ||
'success', | ||
'info' | ||
] | ||
}, | ||
{ | ||
name: 'title', | ||
input: true, | ||
value: 'This message has been identified as spam.', | ||
}, | ||
{ | ||
name: 'isDismissible', | ||
toggle: true, | ||
value: true | ||
} | ||
] | ||
|
||
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() { | ||
let attributes = get(this, 'properties').map((prop) => { | ||
return { | ||
name: prop.name, | ||
value: prop.value, | ||
} | ||
}); | ||
|
||
set(this, 'code', generateCode({ | ||
component: 'nucleus-inline-banner', | ||
attributes, | ||
multiline:true | ||
})); | ||
} | ||
} | ||
|
||
export default Playground; | ||
|
5 changes: 5 additions & 0 deletions
5
packages/@nucleus/tests/dummy/app/components/playground/blank.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({ | ||
|
||
}); |
21 changes: 21 additions & 0 deletions
21
packages/@nucleus/tests/dummy/app/components/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; |
Oops, something went wrong.
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.
This might affect the childrens' text-align and get applied to nucleus-components. Needs some looking into