UNPKG

@up-group/react-controls

Version:

We know that there are a ton of react UI library projects to choose from. Our hope with this one is to provide the next generation of react components that you can use to bootstrap your next project, or as a reference for building a UIKit. Read on to get

200 lines 13 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var _this = this; Object.defineProperty(exports, "__esModule", { value: true }); var React = require("react"); var react_1 = require("@storybook/react"); var theming_1 = require("../../../Common/theming"); var themedComponents_1 = require("../../../Common/theming/themedComponents"); var _1 = require("./"); var Test = (function (_super) { __extends(Test, _super); function Test(p, c) { var _this = _super.call(this, p, c) || this; _this.state = { val: { id: 555, name: "tesdzadzt" }, valM: null, valE: 1, valEM: [1, 2], }; return _this; } Test.prototype.render = function () { var _this = this; return React.createElement(themedComponents_1.ThemeProvider, { theme: theming_1.default }, React.createElement("div", null, React.createElement("div", null, React.createElement("button", { onClick: function () { _this.setState({ val: { id: 5, name: "test" }, valM: [{ id: 1111, name: "test 1" }, { id: 11122, name: "test 2" }], valE: 3, valEM: [3, 4], }); } }, "set test"), React.createElement(_1.default, { autoload: false, isRequired: false, allowClear: true, default: null, multiple: false, tooltip: "Votre ville de naissance", minimumInputLength: 3, value: this.state.val, returnType: "id", dataSource: { query: "https://jsonplaceholder.typicode.com/users", text: "name" }, onChange: function (a) { _this.setState({ val: a, lastChange: a }); } }), React.createElement("div", null, JSON.stringify(this.state.val)), React.createElement(_1.default, { autoload: false, isRequired: false, allowClear: true, default: null, multiple: true, tooltip: "Votre ville de naissance", minimumInputLength: 3, value: this.state.valM, returnType: "id", dataSource: { query: "https://jsonplaceholder.typicode.com/users", text: "name" }, onChange: function (a) { _this.setState({ valM: a, lastChange: a }); } })), React.createElement("div", null, JSON.stringify(this.state.valM)), React.createElement("div", null, React.createElement(_1.default, { width: "normal", value: this.state.valE, returnType: "id", tooltip: "Civilité", default: null, data: [ { id: 1, text: 'M.' }, { id: 2, text: 'Mme' }, { id: 3, text: 'Mlle' }, { id: 4, text: 'Dr' }, ], onChange: function (a) { _this.setState({ valE: a, lastChange: a }); } }), React.createElement("div", null, JSON.stringify(this.state.valE)), React.createElement(_1.default, { value: this.state.valEM, width: "normal", returnType: "id", multiple: true, tooltip: "Civilité", default: null, data: [ { id: 1, text: 'M.' }, { id: 2, text: 'Mme' }, { id: 3, text: 'Mlle' }, { id: 4, text: 'Dr' }, ], onChange: function (a) { _this.setState({ valEM: a, lastChange: a }); } })), React.createElement("div", null, JSON.stringify(this.state.valEM)), React.createElement("div", null, "lastChange", React.createElement("br", null), JSON.stringify(this.state.lastChange)))); }; Test.defaultProps = {}; return Test; }(React.Component)); exports.Test = Test; react_1.storiesOf('UpSelect', module) .addWithInfo('Simple usage', 'Utilisation du composant en lui passant les données à afficher', function () { return (React.createElement(themedComponents_1.ThemeProvider, { theme: theming_1.default }, React.createElement(_1.default, { width: "normal", tooltip: "Civilité", default: null, data: [ { id: 1, text: 'M.' }, { id: 2, text: 'Mme' }, { id: 3, text: 'Mlle' }, { id: 4, text: 'Dr' }, ], onChange: console.log }))); }) .addWithInfo('Set value', 'Utilisation du composant en lui passant les données à afficher', function () { return (React.createElement(Test, null)); }) .addWithInfo('Ajax', 'Utilisation du composant lié à une source de donnée', function () { return (React.createElement(themedComponents_1.ThemeProvider, { theme: theming_1.default }, React.createElement(_1.default, { autoload: false, isRequired: false, allowClear: true, default: null, multiple: false, tooltip: "Votre ville de naissance", minimumInputLength: 3, value: true, returnType: "id", filterOptions: function (options, filter, currentValues) { var _options = []; var _self = _this; options.map(function (value) { if (value['title'].toLowerCase().indexOf(filter.toLowerCase()) >= 0) { var isInValues = false; for (var i in currentValues) { var curentValue = currentValues[i]; if (value[_self.keyId] === curentValue[_self.keyId]) { isInValues = true; break; } } ; if (isInValues === false) _options.push(value); } ; }); return _options; }, dataSource: { query: "https://jsonplaceholder.typicode.com/todos", text: "title" }, onChange: console.log }))); }) .addWithInfo('Ajax avec modification des réponses', 'Utilisation du composant lié à une source de donnée', function () { return (React.createElement(themedComponents_1.ThemeProvider, { theme: theming_1.default }, React.createElement(_1.default, { autoload: false, isRequired: false, allowClear: true, default: null, multiple: false, tooltip: "Votre ville de naissance", minimumInputLength: 3, dataSource: { query: "https://jsonplaceholder.typicode.com/todos", text: "title", handleResponse: function (response) { return [{ id: 100, title: 'Data proxied' }]; } }, onChange: console.log }))); }) .addWithInfo('Required', 'Utilisation du composant avec valeur requise', function () { return (React.createElement(themedComponents_1.ThemeProvider, { theme: theming_1.default }, React.createElement("div", { style: { margin: "30px" } }, React.createElement(_1.default, { isRequired: true, allowClear: true, default: null, multiple: false, tooltip: "Votre ville de naissance", data: [ { id: 1, text: 'M.' }, { id: 2, text: 'Mme' }, { id: 3, text: 'Mlle' }, { id: 4, text: 'Dr' }, ], onChange: console.log })))); }) .addWithInfo('Return Id Value', 'Utilisation du composant en retournant la valeur de l\'identifiant et non plus l\'objet sélectionné', function () { return (React.createElement(themedComponents_1.ThemeProvider, { theme: theming_1.default }, React.createElement("div", { style: { margin: "30px" } }, React.createElement(_1.default, { isRequired: true, allowClear: true, default: null, value: 2, multiple: false, returnType: "id", valueKey: "id", tooltip: "Votre ville de naissance", data: [ { id: 1, text: 'M.' }, { id: 2, text: 'Mme' }, { id: 3, text: 'Mlle' }, { id: 4, text: 'Dr' }, ], onChange: console.log })))); }) .addWithInfo('Size', 'Utilisation du composant en retournant la valeur de l\'identifiant et non plus l\'objet sélectionné', function () { return (React.createElement(themedComponents_1.ThemeProvider, { theme: theming_1.default }, React.createElement("div", { style: { margin: "30px" } }, React.createElement(_1.default, { isRequired: true, allowClear: true, width: 'auto', default: null, multiple: false, returnType: "id", valueKey: "id", tooltip: "Votre ville de naissance", data: [ { id: 1, text: 'M.' }, { id: 2, text: 'Mme' }, { id: 3, text: 'Mlle' }, { id: 4, text: 'Dr' }, ], onChange: console.log }), React.createElement(_1.default, { isRequired: true, allowClear: true, width: 'full', default: null, multiple: false, returnType: "id", valueKey: "id", tooltip: "Votre ville de naissance", data: [ { id: 1, text: 'M.' }, { id: 2, text: 'Mme' }, { id: 3, text: 'Mlle' }, { id: 4, text: 'Dr' }, ], onChange: console.log }), React.createElement(_1.default, { isRequired: true, allowClear: true, width: 'xsmall', default: null, multiple: false, returnType: "id", valueKey: "id", tooltip: "Votre ville de naissance", data: [ { id: 1, text: 'M.' }, { id: 2, text: 'Mme' }, { id: 3, text: 'Mlle' }, { id: 4, text: 'Dr' }, ], onChange: console.log }), React.createElement(_1.default, { isRequired: true, allowClear: true, width: 'small', default: null, multiple: false, returnType: "id", valueKey: "id", tooltip: "Votre ville de naissance", data: [ { id: 1, text: 'M.' }, { id: 2, text: 'Mme' }, { id: 3, text: 'Mlle' }, { id: 4, text: 'Dr' }, ], onChange: console.log }), React.createElement(_1.default, { isRequired: true, allowClear: true, width: 'normal', default: null, multiple: false, returnType: "id", valueKey: "id", tooltip: "Votre ville de naissance", data: [ { id: 1, text: 'M.' }, { id: 2, text: 'Mme' }, { id: 3, text: 'Mlle' }, { id: 4, text: 'Dr' }, ], onChange: console.log }), React.createElement(_1.default, { isRequired: true, allowClear: true, width: 'large', default: null, multiple: false, returnType: "id", valueKey: "id", tooltip: "Votre ville de naissance", data: [ { id: 1, text: 'M.' }, { id: 2, text: 'Mme' }, { id: 3, text: 'Mlle' }, { id: 4, text: 'Dr' }, ], onChange: console.log })))); }) .addWithInfo('Creatable', 'Utilisation du composant avec autorisation de création de nouvelle option', function () { return (React.createElement(themedComponents_1.ThemeProvider, { theme: theming_1.default }, React.createElement("div", { style: { margin: "30px" } }, React.createElement(_1.default, { autoload: false, isRequired: false, allowClear: true, allowCreate: true, default: null, multiple: false, tooltip: "Votre ville de naissance", minimumInputLength: 3, dataSource: { query: "https://jsonplaceholder.typicode.com/todos", text: "title" }, filterOptions: function (options, filter, currentValues) { var _options = []; var _self = _this; options.map(function (value) { if (value['title'].toLowerCase().indexOf(filter.toLowerCase()) >= 0) { var isInValues = false; for (var i in currentValues) { var curentValue = currentValues[i]; if (value[_self.keyId] === curentValue[_self.keyId]) { isInValues = true; break; } } ; if (isInValues === false) _options.push(value); } ; }); return _options; }, onChange: console.log })))); }); //# sourceMappingURL=index.stories.js.map