grommet
Version:
focus on the essential experience
290 lines (262 loc) • 6.92 kB
JavaScript
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
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, { createRef, Component, Fragment } from 'react';
import PropTypes from 'prop-types';
import { storiesOf } from '@storybook/react';
import { Box, Drop, Grommet, Text, ThemeContext } from 'grommet';
import { grommet } from 'grommet/themes';
var OneDrop = function OneDrop(_ref) {
var align = _ref.align,
target = _ref.target;
return React.createElement(Drop, {
align: align,
target: target,
stretch: false
}, React.createElement(Box, {
pad: "small"
}));
};
OneDrop.propTypes = {
align: PropTypes.shape({}).isRequired,
target: PropTypes.shape({}).isRequired
};
var Set =
/*#__PURE__*/
function (_Component) {
_inheritsLoose(Set, _Component);
function Set() {
var _this;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _Component.call.apply(_Component, [this].concat(args)) || this;
_defineProperty(_assertThisInitialized(_this), "targetRef", createRef());
return _this;
}
var _proto = Set.prototype;
_proto.componentDidMount = function componentDidMount() {
this.forceUpdate();
};
_proto.render = function render() {
var _this2 = this;
var _this$props = this.props,
aligns = _this$props.aligns,
label = _this$props.label;
return React.createElement(Box, {
border: true,
pad: "small"
}, React.createElement(Text, null, label), React.createElement(Box, {
margin: "xlarge",
background: "dark-3",
pad: {
horizontal: 'large',
vertical: 'medium'
},
align: "center",
justify: "center",
ref: this.targetRef
}, "\xA0"), this.targetRef.current && React.createElement(Fragment, null, aligns.map(function (align, index) {
return React.createElement(OneDrop // eslint-disable-next-line react/no-array-index-key
, {
key: index,
align: align,
target: _this2.targetRef.current
});
})));
};
return Set;
}(Component);
Set.propTypes = {
aligns: PropTypes.arrayOf(PropTypes.shape({})).isRequired,
label: PropTypes.string.isRequired
};
var AllDrops =
/*#__PURE__*/
function (_Component2) {
_inheritsLoose(AllDrops, _Component2);
function AllDrops() {
var _this3;
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
_this3 = _Component2.call.apply(_Component2, [this].concat(args)) || this;
_defineProperty(_assertThisInitialized(_this3), "targetRef", createRef());
return _this3;
}
var _proto2 = AllDrops.prototype;
_proto2.componentDidMount = function componentDidMount() {
this.forceUpdate();
};
_proto2.render = function render() {
return React.createElement(Grommet, {
theme: grommet
}, React.createElement(ThemeContext.Extend, {
value: {
global: {
drop: {
background: {
color: 'white',
opacity: 'medium'
}
}
}
}
}, React.createElement(Box, {
direction: "row",
wrap: true,
pad: "large",
align: "center",
justify: "center"
}, React.createElement(Set, {
label: "left: left",
aligns: [{
top: 'top',
left: 'left'
}, {
top: 'bottom',
left: 'left'
}, {
bottom: 'top',
left: 'left'
}, {
bottom: 'bottom',
left: 'left'
}]
}), React.createElement(Set, {
label: "left: right",
aligns: [{
top: 'top',
left: 'right'
}, {
top: 'bottom',
left: 'right'
}, {
bottom: 'top',
left: 'right'
}, {
bottom: 'bottom',
left: 'right'
}]
}), React.createElement(Set, {
label: "(center horizontal)",
aligns: [{
top: 'top'
}, {
top: 'bottom'
}, {
bottom: 'top'
}, {
bottom: 'bottom'
}]
}), React.createElement(Set, {
label: "right: left",
aligns: [{
top: 'top',
right: 'left'
}, {
top: 'bottom',
right: 'left'
}, {
bottom: 'top',
right: 'left'
}, {
bottom: 'bottom',
right: 'left'
}]
}), React.createElement(Set, {
label: "right: right",
aligns: [{
top: 'top',
right: 'right'
}, {
top: 'bottom',
right: 'right'
}, {
bottom: 'top',
right: 'right'
}, {
bottom: 'bottom',
right: 'right'
}]
}), React.createElement(Set, {
label: "top: top",
aligns: [{
left: 'left',
top: 'top'
}, {
left: 'right',
top: 'top'
}, {
right: 'left',
top: 'top'
}, {
right: 'right',
top: 'top'
}]
}), React.createElement(Set, {
label: "top: bottom",
aligns: [{
left: 'left',
top: 'bottom'
}, {
left: 'right',
top: 'bottom'
}, {
right: 'left',
top: 'bottom'
}, {
right: 'right',
top: 'bottom'
}]
}), React.createElement(Set, {
label: "(center vertical)",
aligns: [{
left: 'left'
}, {
left: 'right'
}, {
right: 'left'
}, {
right: 'right'
}]
}), React.createElement(Set, {
label: "bottom: top",
aligns: [{
left: 'left',
bottom: 'top'
}, {
left: 'right',
bottom: 'top'
}, {
right: 'left',
bottom: 'top'
}, {
right: 'right',
bottom: 'top'
}]
}), React.createElement(Set, {
label: "bottom: bottom",
aligns: [{
left: 'left',
bottom: 'bottom'
}, {
left: 'right',
bottom: 'bottom'
}, {
right: 'left',
bottom: 'bottom'
}, {
right: 'right',
bottom: 'bottom'
}]
}), React.createElement(Set, {
label: "(center vertical and horizontal)",
aligns: [{}]
}))));
};
return AllDrops;
}(Component);
storiesOf('Drop', module).add('All not stretch', function () {
return React.createElement(AllDrops, null);
});