preview.jsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. import { withJsx } from '@mihkeleidast/storybook-addon-source';
  20. import { themeObject, css, exampleThemes } from '@superset-ui/core';
  21. import { combineReducers, createStore, applyMiddleware, compose } from 'redux';
  22. import thunk from 'redux-thunk';
  23. import { Provider } from 'react-redux';
  24. import reducerIndex from 'spec/helpers/reducerIndex';
  25. import { Global } from '@emotion/react';
  26. import { App, Layout, Space, Content } from 'antd';
  27. import 'src/theme.ts';
  28. import './storybook.css';
  29. export const GlobalStylesOverrides = () => (
  30. <Global
  31. styles={css`
  32. html,
  33. body,
  34. #storybook-root {
  35. margin: 0 !important;
  36. padding: 0 !important;
  37. min-height: 100vh !important;
  38. }
  39. .ant-app {
  40. min-height: 100vh !important;
  41. }
  42. `}
  43. />
  44. );
  45. const store = createStore(
  46. combineReducers(reducerIndex),
  47. {},
  48. compose(applyMiddleware(thunk)),
  49. );
  50. export const globalTypes = {
  51. theme: {
  52. name: 'Theme',
  53. description: 'Global theme for components',
  54. defaultValue: 'superset',
  55. toolbar: {
  56. icon: 'paintbrush',
  57. items: Object.keys(exampleThemes),
  58. },
  59. },
  60. };
  61. const themeDecorator = (Story, context) => {
  62. const themeKey = context.globals.theme || 'superset';
  63. themeObject.setConfig(exampleThemes[themeKey]);
  64. return (
  65. <themeObject.SupersetThemeProvider>
  66. <App>
  67. <GlobalStylesOverrides />
  68. <Layout
  69. style={{
  70. minHeight: '100vh',
  71. width: '100%',
  72. padding: 24,
  73. backgroundColor: themeObject.theme.colorBgBase,
  74. }}
  75. >
  76. <Story {...context} />
  77. </Layout>
  78. </App>
  79. </themeObject.SupersetThemeProvider>
  80. );
  81. };
  82. const providerDecorator = Story => (
  83. <Provider store={store}>
  84. <Story />
  85. </Provider>
  86. );
  87. export const decorators = [withJsx, themeDecorator, providerDecorator];
  88. export const parameters = {
  89. paddings: {
  90. values: [
  91. { name: 'None', value: '0px' },
  92. { name: 'Small', value: '16px' },
  93. { name: 'Medium', value: '32px' },
  94. { name: 'Large', value: '64px' },
  95. ],
  96. default: 'Medium',
  97. },
  98. options: {
  99. storySort: {
  100. order: [
  101. 'Superset Frontend',
  102. ['Controls', 'Display', 'Feedback', 'Input', '*'],
  103. ['Overview', 'Examples', '*'],
  104. 'Design System',
  105. [
  106. 'Introduction',
  107. 'Foundations',
  108. 'Components',
  109. ['Overview', 'Examples', '*'],
  110. 'Patterns',
  111. '*',
  112. ],
  113. ['Overview', 'Examples', '*'],
  114. '*',
  115. ],
  116. },
  117. },
  118. controls: { expanded: true, sort: 'alpha', disableSaveFromUI: true },
  119. };