Browse Source

Experimenting with generating doc for ui component

Dominik Prokop 7 years ago
parent
commit
6d3e6b1fcb

+ 3 - 2
packages/grafana-ui/.storybook/config.ts

@@ -1,8 +1,9 @@
 import { configure } from '@storybook/react';
 import { configure } from '@storybook/react';
-import '../../../public/sass/grafana.dark.scss';
+
+import '@grafana/ui/src/components/index.scss';
 
 
 // automatically import all files ending in *.stories.tsx
 // automatically import all files ending in *.stories.tsx
-const req = require.context('../stories', true, /.story.tsx$/);
+const req = require.context('../src/components', true, /.story.tsx$/);
 
 
 function loadStories() {
 function loadStories() {
   req.keys().forEach(req);
   req.keys().forEach(req);

+ 17 - 0
packages/grafana-ui/.storybook/webpack.config.js

@@ -1,6 +1,7 @@
 const path = require('path');
 const path = require('path');
 
 
 module.exports = (baseConfig, env, config) => {
 module.exports = (baseConfig, env, config) => {
+
   config.module.rules.push({
   config.module.rules.push({
     test: /\.(ts|tsx)$/,
     test: /\.(ts|tsx)$/,
     use: [
     use: [
@@ -9,6 +10,7 @@ module.exports = (baseConfig, env, config) => {
       },
       },
     ],
     ],
   });
   });
+
   config.module.rules.push({
   config.module.rules.push({
     test: /\.scss$/,
     test: /\.scss$/,
     use: [
     use: [
@@ -34,6 +36,21 @@ module.exports = (baseConfig, env, config) => {
       { loader: 'sass-loader', options: { sourceMap: false } },
       { loader: 'sass-loader', options: { sourceMap: false } },
     ],
     ],
   });
   });
+
+  config.module.rules.push({
+    test: require.resolve('jquery'),
+    use: [
+      {
+        loader: 'expose-loader',
+        query: 'jQuery',
+      },
+      {
+        loader: 'expose-loader',
+        query: '$',
+      },
+    ],
+  });
+
   config.resolve.extensions.push('.ts', '.tsx');
   config.resolve.extensions.push('.ts', '.tsx');
   return config;
   return config;
 };
 };

+ 4 - 2
packages/grafana-ui/package.json

@@ -28,7 +28,7 @@
     "tinycolor2": "^1.4.1"
     "tinycolor2": "^1.4.1"
   },
   },
   "devDependencies": {
   "devDependencies": {
-    "@storybook/addon-info": "^4.1.4",
+    "@storybook/addon-info": "^4.1.6",
     "@storybook/react": "^4.1.4",
     "@storybook/react": "^4.1.4",
     "@types/classnames": "^2.2.6",
     "@types/classnames": "^2.2.6",
     "@types/jest": "^23.3.2",
     "@types/jest": "^23.3.2",
@@ -36,13 +36,15 @@
     "@types/lodash": "^4.14.119",
     "@types/lodash": "^4.14.119",
     "@types/node": "^10.12.18",
     "@types/node": "^10.12.18",
     "@types/react": "^16.7.6",
     "@types/react": "^16.7.6",
-    "@types/storybook__react": "^4.0.0",
     "@types/react-custom-scrollbars": "^4.0.5",
     "@types/react-custom-scrollbars": "^4.0.5",
     "@types/react-test-renderer": "^16.0.3",
     "@types/react-test-renderer": "^16.0.3",
     "@types/react-transition-group": "^2.0.15",
     "@types/react-transition-group": "^2.0.15",
+    "@types/storybook__addon-info": "^3.4.2",
+    "@types/storybook__react": "^4.0.0",
     "@types/tether-drop": "^1.4.8",
     "@types/tether-drop": "^1.4.8",
     "@types/tinycolor2": "^1.4.1",
     "@types/tinycolor2": "^1.4.1",
     "awesome-typescript-loader": "^5.2.1",
     "awesome-typescript-loader": "^5.2.1",
+    "react-docgen-typescript-loader": "^3.0.0",
     "react-docgen-typescript-webpack-plugin": "^1.1.0",
     "react-docgen-typescript-webpack-plugin": "^1.1.0",
     "react-test-renderer": "^16.7.0",
     "react-test-renderer": "^16.7.0",
     "typescript": "^3.2.2"
     "typescript": "^3.2.2"

+ 25 - 0
packages/grafana-ui/src/components/ColorPicker/ColorPicker.story.tsx

@@ -0,0 +1,25 @@
+import React, { FunctionComponent } from 'react';
+import { storiesOf } from '@storybook/react';
+import { ColorPicker } from '@grafana/ui';
+import { withInfo } from '@storybook/addon-info';
+
+const CenteredStory: FunctionComponent<{}> = ({ children }) => {
+  return (
+    <div
+      style={{
+        height: '100vh  ',
+        display: 'flex',
+        alignItems: 'center',
+        justifyContent: 'center',
+      }}
+    >
+      {children}
+    </div>
+  );
+};
+
+storiesOf('UI/ColorPicker', module)
+  .addDecorator(story => <CenteredStory>{story()}</CenteredStory>)
+  .add('default', withInfo({inline: true})(() => {
+    return <ColorPicker color="#ff0000" onChange={() => {}} />;
+  }));

+ 10 - 3
packages/grafana-ui/src/components/ColorPicker/ColorPicker.tsx

@@ -1,14 +1,19 @@
-import React from 'react';
+import React, { Component } from 'react';
 import ReactDOM from 'react-dom';
 import ReactDOM from 'react-dom';
 import Drop from 'tether-drop';
 import Drop from 'tether-drop';
 import { ColorPickerPopover } from './ColorPickerPopover';
 import { ColorPickerPopover } from './ColorPickerPopover';
 
 
-export interface Props {
+interface Props {
+  /**
+   * Value to display, either empty (" ") or "X" / "O".
+   *
+   * @default " "
+   **/
   color: string;
   color: string;
   onChange: (c: string) => void;
   onChange: (c: string) => void;
 }
 }
 
 
-export class ColorPicker extends React.Component<Props, any> {
+export class ColorPicker extends Component<Props, any> {
   pickerElem: HTMLElement | null;
   pickerElem: HTMLElement | null;
   colorPickerDrop: any;
   colorPickerDrop: any;
 
 
@@ -59,3 +64,5 @@ export class ColorPicker extends React.Component<Props, any> {
     );
     );
   }
   }
 }
 }
+
+export default ColorPicker;

+ 24 - 0
packages/grafana-ui/src/components/DeleteButton/DeleteButton.story.tsx

@@ -0,0 +1,24 @@
+import React, { FunctionComponent } from 'react';
+import { storiesOf } from '@storybook/react';
+import { DeleteButton } from '@grafana/ui';
+
+const CenteredStory: FunctionComponent<{}> = ({ children }) => {
+  return (
+    <div
+      style={{
+        height: '100vh  ',
+        display: 'flex',
+        alignItems: 'center',
+        justifyContent: 'center',
+      }}
+    >
+      {children}
+    </div>
+  );
+};
+
+storiesOf('UI/DeleteButton', module)
+  .addDecorator(story => <CenteredStory>{story()}</CenteredStory>)
+  .add('default', () => {
+    return <DeleteButton onConfirm={() => {}} />;
+  });

+ 0 - 11
packages/grafana-ui/stories/Test.story.tsx

@@ -1,11 +0,0 @@
-import React from 'react';
-import { storiesOf } from '@storybook/react';
-import { DeleteButton } from '@grafana/ui';
-
-storiesOf('Test story', module)
-.addDecorator((story) => (
-  <div style={{padding: '20px'}}>{story()}</div>
-))
-  .add('with text', () => {
-  return <DeleteButton onConfirm={() => { }}></DeleteButton>;
-});

+ 1 - 1
public/sass/_grafana.scss

@@ -1,4 +1,4 @@
- // DEPENDENCIES
+   // DEPENDENCIES
 @import '../../node_modules/react-table/react-table.css';
 @import '../../node_modules/react-table/react-table.css';
 
 
 // VENDOR
 // VENDOR

File diff suppressed because it is too large
+ 68 - 355
yarn.lock


Some files were not shown because too many files changed in this diff