vcc-ui
Version:
VCC UI is a collection of React UI Components that can be used for developing front-end applications at Volvo Car Corporation.
203 lines (160 loc) • 7.15 kB
JavaScript
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
import React from "react";
import { storiesOf } from "@storybook/react";
import { withBackgrounds } from "@storybook/addon-backgrounds";
import { withKnobs } from "@storybook/addon-knobs";
import { SelectInput } from "../../index";
import { render } from "../../../stories/render";
var listOfLightBackgrounds = [{
name: "white",
value: "#fff",
default: true
}, {
name: "gray",
value: "#ccc"
}];
var options = [{
value: "bilmodell",
label: "I don't have a car"
}, {
value: "c70",
label: "Volvo C70"
}, {
value: "c90",
label: "Volvo C90"
}, {
value: "c99",
label: "Volvo C99",
disabled: true
}, {
value: "c40",
label: "Volvo S40"
}, {
value: "s60",
label: "Volvo S60"
}, {
value: "s80",
label: "Volvo S80"
}, {
value: "s90",
label: "Volvo S90"
}];
storiesOf("SelectInput", module).addDecorator(withBackgrounds(listOfLightBackgrounds)).addDecorator(render).addDecorator(withKnobs).addWithJSX("Basic Example", function () {
var Example =
/*#__PURE__*/
function (_React$Component) {
_inherits(Example, _React$Component);
function Example() {
var _getPrototypeOf2;
var _this;
_classCallCheck(this, Example);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(Example)).call.apply(_getPrototypeOf2, [this].concat(args)));
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "state", {
value: "bilmodell"
});
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "onChange", function (e) {
_this.setState({
value: e.target.value
});
});
return _this;
}
_createClass(Example, [{
key: "render",
value: function render() {
return React.createElement(SelectInput, {
required: true,
value: this.state.value,
onChange: this.onChange.bind(this),
options: options
});
}
}]);
return Example;
}(React.Component);
return React.createElement(Example, null);
}).addWithJSX("With placeholder", function () {
var Example =
/*#__PURE__*/
function (_React$Component2) {
_inherits(Example, _React$Component2);
function Example() {
var _getPrototypeOf3;
var _this2;
_classCallCheck(this, Example);
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
_this2 = _possibleConstructorReturn(this, (_getPrototypeOf3 = _getPrototypeOf(Example)).call.apply(_getPrototypeOf3, [this].concat(args)));
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this2)), "state", {
value: ""
});
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this2)), "onChange", function (e) {
_this2.setState({
value: e.target.value
});
});
return _this2;
}
_createClass(Example, [{
key: "render",
value: function render() {
return React.createElement("form", null, React.createElement(SelectInput, {
placeholder: "Select a Car",
onChange: this.onChange.bind(this),
options: options.slice(1),
value: this.state.value
}));
}
}]);
return Example;
}(React.Component);
return React.createElement(Example, null);
}).addWithJSX("No initial value, no placeholder", function () {
var Example =
/*#__PURE__*/
function (_React$Component3) {
_inherits(Example, _React$Component3);
function Example() {
var _getPrototypeOf4;
var _this3;
_classCallCheck(this, Example);
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
args[_key3] = arguments[_key3];
}
_this3 = _possibleConstructorReturn(this, (_getPrototypeOf4 = _getPrototypeOf(Example)).call.apply(_getPrototypeOf4, [this].concat(args)));
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this3)), "state", {
value: ""
});
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this3)), "onChange", function (e) {
_this3.setState({
value: e.target.value
});
});
return _this3;
}
_createClass(Example, [{
key: "render",
value: function render() {
return React.createElement(SelectInput, {
onChange: this.onChange.bind(this),
options: options
});
}
}]);
return Example;
}(React.Component);
return React.createElement(Example, null);
});