Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[canvas] Color fixes + Storybook 5 #34075

Merged
merged 10 commits into from
Apr 2, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/__snapshots__/** linguist-generated=true
20 changes: 11 additions & 9 deletions x-pack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@
"@kbn/expect": "1.0.0",
"@kbn/plugin-helpers": "9.0.2",
"@kbn/test": "1.0.0",
"@storybook/addon-actions": "^4.1.7",
"@storybook/addon-actions": "^5.0.5",
"@storybook/addon-console": "^1.1.0",
"@storybook/addon-info": "^4.0.7",
"@storybook/addon-knobs": "^4.0.7",
"@storybook/addon-options": "^4.1.7",
"@storybook/addon-storyshots": "^4.1.7",
"@storybook/react": "^4.0.7",
"@storybook/addon-info": "^5.0.5",
"@storybook/addon-knobs": "^5.0.5",
"@storybook/addon-options": "^5.0.5",
"@storybook/addon-storyshots": "^5.0.5",
"@storybook/react": "^5.0.5",
"@storybook/theming": "^5.0.5",
"@types/angular": "1.6.50",
"@types/cheerio": "^0.22.10",
"@types/chroma-js": "^1.4.1",
Expand Down Expand Up @@ -65,9 +66,10 @@
"@types/recompose": "^0.30.2",
"@types/reduce-reducers": "^0.1.3",
"@types/sinon": "^5.0.1",
"@types/storybook__addon-actions": "^3.4.1",
"@types/storybook__addon-info": "^3.4.2",
"@types/storybook__react": "^4.0.0",
"@types/storybook__addon-actions": "^3.4.2",
"@types/storybook__addon-info": "^4.1.1",
"@types/storybook__addon-knobs": "^4.0.4",
"@types/storybook__react": "^4.0.1",
"@types/supertest": "^2.0.5",
"@types/tinycolor2": "^1.4.1",
"@types/uuid": "^3.4.4",
Expand Down
41 changes: 25 additions & 16 deletions x-pack/plugins/canvas/.storybook/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { configure, addDecorator } from '@storybook/react';
import { configure, addDecorator, addParameters } from '@storybook/react';
import { withKnobs } from '@storybook/addon-knobs/react';
import { withInfo } from '@storybook/addon-info';
import { withOptions } from '@storybook/addon-options';
import { create } from '@storybook/theming';

// Import dependent CSS
require('@elastic/eui/dist/eui_theme_light.css');
Expand All @@ -21,16 +21,16 @@ if (process.env.NODE_ENV === 'test') {
} else {
// Customize the info for each story.
addDecorator(
withInfo({
withInfo({
inline: true,
styles: {
infoBody: {
margin: 20
margin: 20,
},
infoStory: {
margin: '40px 60px'
}
}
margin: '40px 60px',
},
},
})
);

Expand All @@ -44,7 +44,11 @@ function loadStories() {
css.keys().forEach(filename => css(filename));

// Include the legacy styles
const uiStyles = require.context('../../../../src/legacy/ui/public/styles', false, /[\/\\](?!mixins|variables|_|\.|bootstrap_(light|dark))[^\/\\]+\.less/);
const uiStyles = require.context(
'../../../../src/legacy/ui/public/styles',
false,
/[\/\\](?!mixins|variables|_|\.|bootstrap_(light|dark))[^\/\\]+\.less/
);
uiStyles.keys().forEach(key => uiStyles(key));

// Find all files ending in *.examples.ts
Expand All @@ -53,13 +57,18 @@ function loadStories() {
}

// Set up the Storybook environment with custom settings.
addDecorator(
withOptions({
goFullScreen: false,
name: 'Canvas Storybook',
showAddonsPanel: true,
url: 'https://github.com/elastic/kibana/tree/master/x-pack/plugins/canvas'
})
);
addParameters({
options: {
theme: create({
base: 'light',
brandTitle: 'Canvas Storybook',
brandUrl: 'https://github.com/elastic/kibana/tree/master/x-pack/plugins/canvas',
}),
showPanel: true,
isFullscreen: false,
panelPosition: 'bottom',
isToolshown: true,
},
});

configure(loadStories, module);
37 changes: 14 additions & 23 deletions x-pack/plugins/canvas/.storybook/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,16 @@ const path = require('path');
const TSDocgenPlugin = require('react-docgen-typescript-webpack-plugin');

// Extend the Storybook Webpack config with some customizations;
module.exports = (_baseConfig, _env, config) => {

module.exports = async ({ config, _mode }) => {
// Include the React preset for Storybook JS files.
config.module.rules.push(
{
test: /\.js$/,
include: /\.storybook/,
loaders: 'babel-loader',
options: {
presets: [require.resolve('@babel/preset-react')],
},
config.module.rules.push({
test: /\.js$/,
exclude: /node_modules/,
loaders: 'babel-loader',
options: {
presets: [require.resolve('@kbn/babel-preset/webpack_preset')],
},
);
});

// Find and alter the CSS rule to replace the Kibana public path string with a path
// to the route we've added in middleware.js
Expand All @@ -30,10 +27,10 @@ module.exports = (_baseConfig, _env, config) => {
options: {
search: '__REPLACE_WITH_PUBLIC_PATH__',
replace: '/',
flags: 'g'
}
flags: 'g',
},
});

// Configure loading LESS files from Kibana
config.module.rules.push({
test: /\.less$/,
Expand All @@ -55,15 +52,9 @@ module.exports = (_baseConfig, _env, config) => {
test: /\.tsx?$/,
use: [
{
loader: 'ts-loader',
loader: 'babel-loader',
options: {
transpileOnly: true,
experimentalWatchApi: true,
onlyCompileBundledFiles: true,
configFile: require.resolve('../../../../tsconfig.json'),
compilerOptions: {
sourceMap: true,
},
presets: [require.resolve('@kbn/babel-preset/webpack_preset')],
},
},
require.resolve('react-docgen-typescript-loader'),
Expand All @@ -72,7 +63,7 @@ module.exports = (_baseConfig, _env, config) => {

// Include the TSDocgen plugin to display Typescript param comments in the stories.
config.plugins.push(new TSDocgenPlugin());

// Tell Webpack about the ts/x extensions
config.resolve.extensions.push('.ts', '.tsx');

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions x-pack/plugins/canvas/public/components/color_dot/color_dot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,28 @@
*/

import PropTypes from 'prop-types';
import React, { ReactNode, SFC } from 'react';
import React, { FunctionComponent, ReactNode } from 'react';
import tinycolor from 'tinycolor2';

export interface Props {
/** Any valid CSS color. If not a valid CSS string, the dot will not render */
value: string;
/** Any valid CSS color. If not a valid CSS string, the dot will be transparent and checkered */
value?: string;
/** Nodes to display within the dot. Should fit within the constraints. */
children?: ReactNode;
}

export const ColorDot: SFC<Props> = ({ value, children }) => {
export const ColorDot: FunctionComponent<Props> = ({ value, children }) => {
const tc = tinycolor(value);
if (!tc.isValid()) {
return null;
let style = {};

if (tc.isValid()) {
style = { background: value };
}

return (
<div className="canvasColorDot">
<div className="canvasColorDot__background canvasCheckered" />
<div className="canvasColorDot__foreground" style={{ background: tc.toRgbString() }}>
<div className="canvasColorDot__foreground" style={style}>
{children}
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/canvas/public/components/color_dot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ import { pure } from 'recompose';

import { ColorDot as Component } from './color_dot';

export { Props } from './color_dot';
export const ColorDot = pure(Component);
Loading