Skip to content

Commit

Permalink
add customiser initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
rcaferati committed Feb 19, 2018
1 parent cc5ada2 commit bd0def8
Show file tree
Hide file tree
Showing 11 changed files with 390 additions and 84 deletions.
13 changes: 4 additions & 9 deletions src/components/AwesomeButton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,18 +269,13 @@ export default class AwesomeButton extends React.Component {
>
<span
ref={(button) => { this.button = button; }}
className={getClassName(`${this.rootElement}__container`, cssModule)}
className={getClassName(`${this.rootElement}__wrapper`, cssModule)}
>
<span
ref={(wrapper) => { this.wrapper = wrapper; }}
className={getClassName(`${this.rootElement}__wrapper`, cssModule)}
ref={(content) => { this.content = content; }}
className={getClassName(`${this.rootElement}__content`, cssModule)}
>
<span
ref={(content) => { this.content = content; }}
className={getClassName(`${this.rootElement}__content`, cssModule)}
>
<span>{children}</span>
</span>
<span ref={(child) => { this.child = child; }}>{children}</span>
</span>
</span>
</RenderComponent>
Expand Down
44 changes: 27 additions & 17 deletions src/components/AwesomeButtonProgress/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export default class AwesomeProgress extends React.Component {
super(props);
this.rootElement = props.rootElement || ROOTELM;
this.animationStage = 0;
this.loading = false;
this.state = {
loading: false,
loadingEnd: false,
loadingStart: false,
blocked: false,
Expand All @@ -61,36 +61,48 @@ export default class AwesomeProgress extends React.Component {
return className.join(' ').trim().replace(/[\s]+/ig, ' ');
}
endLoading() {
this.setState({ loadingEnd: true });
this.setState({
loadingEnd: true,
});
this.animationStage = 1;
}
startLoading() {
this.loading = true;
this.setState({
loading: true,
loadingStart: true,
blocked: true,
active: true,
}, () => {
/*
To avoid the button eventual flickering I've changed the display strategy
for that to work in a controlled way we need to set the loadingStart
at least one painting cycle ahead
*/
window.requestAnimationFrame(() => {
window.requestAnimationFrame(() => {
this.setState({
loadingStart: true,
});
});
});
});
}
clearLoading() {
clearLoading(callback) {
this.loading = false;
this.setState({
loading: false,
loadingStart: false,
loadingEnd: false,
});
active: false,
}, callback);
}
clearStagedWrapperAnimation() {
if (this.animationStage !== 0) {
if (this.animationStage === LOADING_ANIMATION_STEPS) {
this.animationStage = 0;
// hold life for 350ms before releasing the button;
// hold life for 500ms before releasing the button;
setTimeout(() => {
if (typeof window !== 'undefined') {
window.requestAnimationFrame(() => {
this.clearLoading();
this.setState({
active: false,
}, () => {
this.clearLoading(() => {
setTimeout(() => {
this.setState({
blocked: false,
Expand Down Expand Up @@ -118,19 +130,17 @@ export default class AwesomeProgress extends React.Component {
const events = {
onMouseDown: (event) => {
if (this.state.disabled === true ||
this.state.loading === true ||
this.loading === true ||
this.state.blocked === true ||
(event && event.nativeEvent.which !== 1)
) {
return;
}
this.setState({
loading: true,
});
this.loading = true;
},
onMouseUp: (event) => {
if (this.state.disabled === true ||
this.state.loading === true ||
this.loading === true ||
this.state.blocked === true) {
event.preventDefault();
event.stopPropagation();
Expand Down
178 changes: 178 additions & 0 deletions src/demo/components/customiser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
import React from 'react';
import PropTypes from 'prop-types';

const PROPERTIES = [
{
name: 'button-color-primary',
type: 'color',
},
{
name: 'button-color-primary-dark',
type: 'color',
},
{
name: 'button-color-primary-light',
type: 'color',
},
{
name: 'button-color-primary-border',
type: 'color',
},
{
name: 'button-color-secondary',
type: 'color',
},
{
name: 'button-color-secondary-dark',
type: 'color',
},
{
name: 'button-color-secondary-light',
type: 'color',
},
{
name: 'button-color-secondary-border',
type: 'color',
},
{
name: 'button-default-height',
type: 'range',
max: 100,
min: 30,
suffix: 'px',
},
{
name: 'button-default-font-size',
type: 'range',
max: 25,
min: 10,
suffix: 'px',
},
{
name: 'button-default-border-radius',
type: 'range',
max: 25,
suffix: 'px',
},
{
name: 'button-horizontal-padding',
type: 'range',
max: 50,
suffix: 'px',
},
{
name: 'button-raise-level',
type: 'range',
max: 10,
suffix: 'px',
},
{
name: 'button-hover-pressure',
type: 'range',
max: 4,
step: 0.5,
},
];

function applyStyles(buttons, { property, value }) {
buttons.forEach((button) => {
button.style.setProperty(property, value);
});
}

class Customiser extends React.Component {
static propTypes = {
styles: PropTypes.object.isRequired,
theme: PropTypes.string.isRequired,
};
constructor(props) {
super(props);
this.state = {
buttonSample: null,
'--button-color-primary': null,
};
}

componentDidMount() {
this.setState({
buttonSample: document.querySelector('button'),
allButtons: document.querySelectorAll('button'),
});
}

handleChange = () => {
console.log('change-made');
}

renderInputs() {
return PROPERTIES.map((cssProperty) => {
const { name, type } = cssProperty;
const buttonName = `--${name}`;

if (!this.state[buttonName] && this.state.buttonSample) {
const state = {};
let style = getComputedStyle(this.state.buttonSample).getPropertyValue(buttonName);
if (style.match(/(#)([a-z0-9]{3})($)/)) {
style = style.replace(/(#)([a-z0-9]{3})/, '$1$2$2');
}
if (style.match(/px|em/)) {
style = style.replace(/px|em/ig, '')
}
state[buttonName] = style;
this.setState(state);
}

const extraProps = {};
extraProps.type = type;

if (type === 'range') {
extraProps.type = type;
extraProps.min = cssProperty.min || 0;
extraProps.max = cssProperty.max || 10;
extraProps.step = cssProperty.step || 1;
}

return (
<li>
<label>
<code>{buttonName}</code>
</label>
<input
id="button-primary-color"
value={this.state[buttonName] || ''}
onChange={(event) => {
const state = {};
let { value } = event.target;
state[buttonName] = value;
this.setState(state);
if (cssProperty.suffix) {
value = `${value}${cssProperty.suffix}`;
}
applyStyles(this.state.allButtons, {
property: buttonName,
value,
});
}}
{... extraProps}
/>
</li>
);
});
}

render() {
const {
styles,
} = this.props;

return (
<section className={styles.customiser}>
<ul>
{ this.renderInputs() }
</ul>
</section>
);
}
}

export default Customiser;
33 changes: 14 additions & 19 deletions src/demo/components/theme-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { AwesomeButton, AwesomeButtonSocial } from '../../index';
import { AwesomeButton, AwesomeButtonSocial, AwesomeButtonProgress } from '../../index';
import Modules from '../../helpers/modules';

class Test extends React.Component {
Expand Down Expand Up @@ -28,32 +28,32 @@ class Test extends React.Component {
<section className={styles.container}>
<div className={styles.section}>
<AwesomeButton
bubbles
cssModule={Module}
>
<i className="fa fa-codepen" aria-hidden /> Primary
</AwesomeButton>
</div>
<div className={styles.section}>
<AwesomeButton
bubbles
cssModule={Module}
type="secondary"
>
<i className="fa fa-hand-spock-o" aria-hidden /> Secondary
Secondary
</AwesomeButton>
</div>
<div className={styles.section}>
<AwesomeButton
<AwesomeButtonProgress
cssModule={Module}
progress
size="large"
type="primary"
action={(element, next) => {
setTimeout(() => {
// debugger;
next();
}, 1000);
}, 750);
}}
>
Progress
</AwesomeButton>
</AwesomeButtonProgress>
</div>
<div className={`${styles.loadData} ${styles.section}`}>
<AwesomeButton
Expand All @@ -74,7 +74,7 @@ class Test extends React.Component {
});
}}
>
← Set Placeholder Data
← Set Data
</span>
</div>
<div className={`${styles.loadData} ${styles.section}`}>
Expand Down Expand Up @@ -110,6 +110,8 @@ class Test extends React.Component {
>
Share
</AwesomeButtonSocial>
</div>
<div className={styles.section}>
<AwesomeButtonSocial
iconHeight="24px"
iconWidth="26px"
Expand All @@ -120,15 +122,8 @@ class Test extends React.Component {
>
Share
</AwesomeButtonSocial>
<AwesomeButtonSocial
iconHeight="24px"
iconWidth="26px"
type="reddit"
url="https://caferati.me"
cssModule={Module}
>
Share
</AwesomeButtonSocial>
</div>
<div className={styles.section}>
<AwesomeButtonSocial
iconHeight="24px"
iconWidth="26px"
Expand Down
Loading

0 comments on commit bd0def8

Please sign in to comment.