UNPKG

6.77 kBJavaScriptView Raw
1import "core-js/modules/es.array.index-of.js";
2import "core-js/modules/es.array.map.js";
3import "core-js/modules/es.object.assign.js";
4import "core-js/modules/es.object.keys.js";
5import "core-js/modules/es.object.values.js";
6import "core-js/modules/es.string.bold.js";
7
8function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
9
10function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
11
12function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
13
14import React from 'react';
15import { styled } from '@storybook/theming';
16import { transparentize } from 'polished';
17import { getBlockBackgroundStyle } from './BlockBackgroundStyles';
18import { ResetWrapper } from '../typography/DocumentFormatting';
19var ItemTitle = styled.div(function (_ref) {
20 var theme = _ref.theme;
21 return {
22 fontWeight: theme.typography.weight.bold,
23 color: theme.color.defaultText
24 };
25});
26var ItemSubtitle = styled.div(function (_ref2) {
27 var theme = _ref2.theme;
28 return {
29 color: theme.base === 'light' ? transparentize(0.2, theme.color.defaultText) : transparentize(0.6, theme.color.defaultText)
30 };
31});
32var ItemDescription = styled.div({
33 flex: '0 0 30%',
34 lineHeight: '20px',
35 marginTop: 5
36});
37var SwatchLabel = styled.div(function (_ref3) {
38 var theme = _ref3.theme;
39 return {
40 flex: 1,
41 textAlign: 'center',
42 fontFamily: theme.typography.fonts.mono,
43 fontSize: theme.typography.size.s1,
44 lineHeight: 1,
45 overflow: 'hidden',
46 color: theme.base === 'light' ? transparentize(0.4, theme.color.defaultText) : transparentize(0.6, theme.color.defaultText),
47 '> div': {
48 display: 'inline-block',
49 overflow: 'hidden',
50 maxWidth: '100%',
51 textOverflow: 'ellipsis'
52 },
53 span: {
54 display: 'block',
55 marginTop: 2
56 }
57 };
58});
59var SwatchLabels = styled.div({
60 display: 'flex',
61 flexDirection: 'row'
62});
63var Swatch = styled.div({
64 flex: 1
65});
66var SwatchColors = styled.div(function (_ref4) {
67 var theme = _ref4.theme;
68 return Object.assign({}, getBlockBackgroundStyle(theme), {
69 display: 'flex',
70 flexDirection: 'row',
71 height: 50,
72 marginBottom: 5,
73 overflow: 'hidden'
74 });
75});
76var SwatchSpecimen = styled.div({
77 display: 'flex',
78 flexDirection: 'column',
79 flex: 1,
80 position: 'relative',
81 marginBottom: 30
82});
83var Swatches = styled.div({
84 flex: 1,
85 display: 'flex',
86 flexDirection: 'row'
87});
88var Item = styled.div({
89 display: 'flex',
90 alignItems: 'flex-start'
91});
92var ListName = styled.div({
93 flex: '0 0 30%'
94});
95var ListSwatches = styled.div({
96 flex: 1
97});
98var ListHeading = styled.div(function (_ref5) {
99 var theme = _ref5.theme;
100 return {
101 display: 'flex',
102 flexDirection: 'row',
103 alignItems: 'center',
104 paddingBottom: 20,
105 fontWeight: theme.typography.weight.bold,
106 color: theme.base === 'light' ? transparentize(0.4, theme.color.defaultText) : transparentize(0.6, theme.color.defaultText)
107 };
108});
109var List = styled.div(function (_ref6) {
110 var theme = _ref6.theme;
111 return {
112 fontSize: theme.typography.size.s2,
113 lineHeight: "20px",
114 display: 'flex',
115 flexDirection: 'column'
116 };
117});
118
119function renderSwatch(color) {
120 return /*#__PURE__*/React.createElement(Swatch, {
121 key: color,
122 title: color,
123 style: {
124 background: color
125 }
126 });
127}
128
129renderSwatch.displayName = "renderSwatch";
130
131function renderSwatchLabel(color, colorDescription) {
132 return /*#__PURE__*/React.createElement(SwatchLabel, {
133 key: color,
134 title: color
135 }, /*#__PURE__*/React.createElement("div", null, color, colorDescription && /*#__PURE__*/React.createElement("span", null, colorDescription)));
136}
137
138renderSwatchLabel.displayName = "renderSwatchLabel";
139
140function renderSwatchSpecimen(colors) {
141 if (Array.isArray(colors)) {
142 return /*#__PURE__*/React.createElement(SwatchSpecimen, null, /*#__PURE__*/React.createElement(SwatchColors, null, colors.map(function (color) {
143 return renderSwatch(color);
144 })), /*#__PURE__*/React.createElement(SwatchLabels, null, colors.map(function (color) {
145 return renderSwatchLabel(color);
146 })));
147 }
148
149 return /*#__PURE__*/React.createElement(SwatchSpecimen, null, /*#__PURE__*/React.createElement(SwatchColors, null, Object.values(colors).map(function (color) {
150 return renderSwatch(color);
151 })), /*#__PURE__*/React.createElement(SwatchLabels, null, Object.keys(colors).map(function (color) {
152 return renderSwatchLabel(color, colors[color]);
153 })));
154}
155
156renderSwatchSpecimen.displayName = "renderSwatchSpecimen";
157
158/**
159 * A single color row your styleguide showing title, subtitle and one or more colors, used
160 * as a child of `ColorPalette`.
161 */
162export var ColorItem = function ColorItem(_ref7) {
163 var title = _ref7.title,
164 subtitle = _ref7.subtitle,
165 colors = _ref7.colors;
166 return /*#__PURE__*/React.createElement(Item, null, /*#__PURE__*/React.createElement(ItemDescription, null, /*#__PURE__*/React.createElement(ItemTitle, null, title), /*#__PURE__*/React.createElement(ItemSubtitle, null, subtitle)), /*#__PURE__*/React.createElement(Swatches, null, renderSwatchSpecimen(colors)));
167};
168ColorItem.displayName = "ColorItem";
169
170/**
171 * Styleguide documentation for colors, including names, captions, and color swatches,
172 * all specified as `ColorItem` children of this wrapper component.
173 */
174export var ColorPalette = function ColorPalette(_ref8) {
175 var children = _ref8.children,
176 props = _objectWithoutProperties(_ref8, ["children"]);
177
178 return /*#__PURE__*/React.createElement(ResetWrapper, null, /*#__PURE__*/React.createElement(List, _extends({}, props, {
179 className: "docblock-colorpalette"
180 }), /*#__PURE__*/React.createElement(ListHeading, null, /*#__PURE__*/React.createElement(ListName, null, "Name"), /*#__PURE__*/React.createElement(ListSwatches, null, "Swatches")), children));
181};
182ColorPalette.displayName = "ColorPalette";
\No newline at end of file