Skip to content

Commit

Permalink
Merge pull request #49 from b2wads/develop
Browse files Browse the repository at this point in the history
Release 6.1.0
  • Loading branch information
Ana Azevedo authored Sep 18, 2019
2 parents fd0621e + d588ba3 commit 0589148
Show file tree
Hide file tree
Showing 26 changed files with 1,031 additions and 1,851 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Node CI

on: [push]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [8.x]

steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: test build
run: |
yarn
yarn test
env:
CI: true
17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grimorio-ui",
"sideEffects": false,
"version": "6.0.2",
"version": "6.1.0",
"description": "React UI Kit that works like magic",
"main": "lib/index.js",
"scripts": {
Expand All @@ -16,7 +16,6 @@
"lint:styl": "stylint source/",
"lint:js": "eslint source/",
"precommit": "yarn lint",
"prepush": "yarn test",
"release": "./node_modules/.bin/release-it",
"storybook": "./node_modules/.bin/cross-env THEME_ENV=$THEME_ENV start-storybook -p 9000",
"test": "./node_modules/.bin/cross-env NODE_ENV=testing BABEL_ENV=testing jest",
Expand Down Expand Up @@ -65,24 +64,24 @@
"cpy-cli": "2.0.0",
"cross-env": "^5.2.0",
"css-loader": "0.28.4",
"enzyme": "3.3.0",
"enzyme-adapter-react-16": "1.2.0",
"enzyme-to-json": "3.3.5",
"enzyme": "3.3.0",
"eslint": "4.19.0",
"eslint-config-google": "0.9.1",
"eslint-loader": "2.0.0",
"eslint-plugin-import": "2.8.0",
"eslint-plugin-prettier": "2.3.1",
"eslint-plugin-react": "7.5.1",
"eslint": "4.19.0",
"extract-text-webpack-plugin": "3.0.2",
"file-loader": "0.11.2",
"husky": "0.14.3",
"identity-obj-proxy": "3.0.0",
"imports-loader": "0.8.0",
"jest-css-modules-transform": "1.0.5",
"jest": "24.1.0",
"jest-css-modules": "1.1.0",
"jest-css-modules-transform": "1.0.5",
"jest-dot-reporter": "1.0.3",
"jest": "24.1.0",
"jsdom": "9.12.0",
"npm-run-all": "4.1.2",
"postcss-cssnext": "3.0.2",
Expand All @@ -93,11 +92,11 @@
"rimraf": "2.6.2",
"style-loader": "0.17.0",
"stylint": "1.5.9",
"stylus-loader": "3.0.2",
"stylus": "0.54.5",
"stylus-loader": "3.0.2",
"svg-react-loader": "0.4.5",
"webpack-bundle-analyzer": "3.0.3",
"webpack": "3.5.2"
"webpack": "3.5.2",
"webpack-bundle-analyzer": "3.0.3"
},
"dependencies": {
"chart.js": "2.7.3",
Expand Down
8 changes: 6 additions & 2 deletions source/components/accordion/accordion.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,17 @@ stories.add(
active={getActive(0)}
index={0}
onClick={handleClick}
>Um --</AccordionTitle>
>
Um --
</AccordionTitle>
<AccordionContent active={getActive(0)}>primeiro conteudo --</AccordionContent>
<AccordionTitle
active={getActive(1)}
index={1}
onClick={handleClick}
>Dois --</AccordionTitle>
>
Dois --
</AccordionTitle>
<AccordionContent active={getActive(1)}>segundo conteudo --</AccordionContent>
</Accordion>
)
Expand Down
131 changes: 131 additions & 0 deletions source/components/editable-value/editable-value-component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import React, { PureComponent, Fragment } from 'react';
import PropTypes from 'prop-types';
import CSSModules from 'react-css-modules';
import cx from 'classnames';

import Icon from '../icon';
import Button from '../button';
import Loader from '../loader';
import { FormControlLabel, FormGroup, FormHelpText } from '../form';

import styles from './editable-value.styl';

class EditableValue extends PureComponent {
constructor(props) {
super();
this.state = {
isEditing: null,
editValue: null,
innerValue: props.initialValue,
validationStatus: null,
};

this.toggleEdit = this.toggleEdit.bind(this);
this.onSubmit = this.onSubmit.bind(this);
this.changeFieldValue = this.changeFieldValue.bind(this);
}

static propTypes = {
value: PropTypes.string,
initialValue: PropTypes.string,
validation: PropTypes.func,
errorMessage: PropTypes.string,
loading: PropTypes.bool,
onSubmit: PropTypes.func,
label: PropTypes.string,
outline: PropTypes.bool,
inputClassName: PropTypes.string,
buttonClassName: PropTypes.string,
iconClassName: PropTypes.string,
};

static defaultProps = {
outline: false,
loading: false,
};

validation() {
const { editValue } = this.state;
const isValid = this.props.validation ? this.props.validation(editValue) : true;

if (!isValid) {
return { validationStatus: 'error' };
}

return { validationStatus: null };
}

toggleEdit() {
this.setState({ isEditing: !this.state.isEditing, validationStatus: null, editValue: null });
}

onSubmit() {
const { editValue } = this.state;
const { validationStatus } = this.validation(editValue);

if (!this.isValid(editValue)) {
this.toggleEdit();
} else if (validationStatus !== 'error') {
this.setState({ innerValue: editValue });
this.props.onSubmit(editValue, this.toggleEdit);
} else {
this.setState({ validationStatus });
}
}

changeFieldValue(evt) {
this.setState({ editValue: evt.target.value });
}

isValid(value) {
return value !== null && value !== undefined;
}

renderEdition() {
const { label, value, outline, loading, inputClassName, buttonClassName, errorMessage } = this.props;
const { editValue, innerValue, validationStatus } = this.state;
const finalValue = value || innerValue;
return (
<Fragment>
<FormGroup key={validationStatus} validationState={validationStatus} className={styles.formGroup}>
<FormControlLabel
onChange={this.changeFieldValue}
disabled={loading}
outline={outline}
label={label}
type="text"
value={this.isValid(editValue) ? editValue : finalValue}
inputClassName={cx(styles.input, inputClassName)}
/>
{validationStatus === 'error' && errorMessage && <FormHelpText>{errorMessage}</FormHelpText>}
</FormGroup>
<Button className={cx(styles.submit, buttonClassName)} size="none" onClick={this.onSubmit}>
{!loading ? <Icon name="check" size={16} /> : <Loader size="20px" color="secondary" />}
</Button>
</Fragment>
);
}

renderValue() {
const { value, iconClassName } = this.props;
return (
<Fragment>
{value || this.state.innerValue}
<Button className={cx(styles.edit, iconClassName)} size="none" color="transparent" onClick={this.toggleEdit}>
<Icon name="edit" size={16} />
</Button>
</Fragment>
);
}

render() {
const { isEditing } = this.state;
return (
<div className={cx(styles.wrap, { [styles.isEditing]: isEditing }, this.props.className)}>
{isEditing ? this.renderEdition() : this.renderValue()}
</div>
);
}
}

export default CSSModules(EditableValue, styles);
16 changes: 16 additions & 0 deletions source/components/editable-value/editable-value.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import '../../../internals/test/helper';

import EditableValue from './editable-value-component';

/** @test {EditableValue} */
describe('EditableValue component', () => {
/** @test {EditableValue#render} */
describe('#render', () => {
it('render correctly', () => {
const wrapper = shallow(
<EditableValue />
);
expect(wrapper.length).toEqual(1);
});
});
});
109 changes: 109 additions & 0 deletions source/components/editable-value/editable-value.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import React from 'react';
import { storiesOf } from '@storybook/react';
import { withKnobs } from '@storybook/addon-knobs';
import { withState } from '@dump247/storybook-state';

import EditableValue from './editable-value-component';
import Button from '../button';

const stories = storiesOf('EditableValue', module);

stories.addDecorator(withKnobs);

stories.add('Default', () => (
<EditableValue
initialValue="Default"
onSubmit={(value, toggleFn) => {
console.log('onSubmit', value);
toggleFn();
}}
/>
));

stories.add('Outline', () => (
<EditableValue
outline
initialValue="Outline"
onSubmit={(value, toggleFn) => {
console.log('onSubmit', value);
toggleFn();
}}
validation={value => `${value}`.length === 4}
errorMessage="Favor inserir 4 caracteres"
/>
));

stories.add('Label', () => (
<div>
<EditableValue
outline
label="Teste"
initialValue="Outline"
onSubmit={(value, toggleFn) => {
console.log('onSubmit', value);
toggleFn();
}}
validation={value => `${value}`.length === 4}
errorMessage="Favor inserir 4 caracteres"
/>
<br/>
<br/>
<br/>
<br/>
<EditableValue
label="Teste"
initialValue="No Outline"
onSubmit={(value, toggleFn) => {
console.log('onSubmit', value);
toggleFn();
}}
validation={value => `${value}`.length === 4}
errorMessage="Favor inserir 4 caracteres"
/>
</div>
));

stories.add('Uncontrolled', () => (
<EditableValue
label="Uncontrolled"
initialValue="Valor interno"
onSubmit={(value, toggleFn) => {
console.log('onSubmit', value);
toggleFn();
}}
validation={value => `${value}`.length === 4}
errorMessage="Favor inserir 4 caracteres"
/>
));

stories.add(
'Controlled',
withState({ loading: false, value: 'Valor no estado (externo)' })(({ store }) => {
const setVal = (value, toggle) => {
store.set({ loading: true });
setTimeout(() => {
store.set({ value, loading: false });
toggle();
}, 1000);
};

const changeVal = () => {
store.set({ value: 'Novo Valor do Estado' });
};

return (
<div>
<EditableValue
loading={store.state.loading}
value={store.state.value}
onSubmit={setVal}
validation={value => `${value}`.length > 4}
errorMessage="Favor inserir mais que 4 caracteres"
/>
<br/>
<br/>
<Button onClick={changeVal}>Change State Value</Button>
</div>
);
})
);
Loading

0 comments on commit 0589148

Please sign in to comment.