overleaf/services/web/.storybook/main.ts

130 lines
3.9 KiB
TypeScript
Raw Normal View History

import type { StorybookConfig } from '@storybook/react-webpack5'
import path from 'node:path'
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
const rootDir = path.resolve(__dirname, '..')
// NOTE: must be set before webpack config is imported
process.env.OVERLEAF_CONFIG = path.join(rootDir, 'config/settings.webpack.js')
function getAbsolutePath(value: string): any {
return path.dirname(require.resolve(path.join(value, 'package.json')))
}
const config: StorybookConfig = {
core: {
disableTelemetry: true,
},
staticDirs: [path.join(rootDir, 'public')],
stories: [
path.join(rootDir, 'frontend/stories/**/*.stories.{js,jsx,ts,tsx}'),
path.join(rootDir, 'modules/**/stories/**/*.stories.{js,jsx,ts,tsx}'),
],
addons: [
getAbsolutePath('@storybook/addon-links'),
getAbsolutePath('@storybook/addon-essentials'),
getAbsolutePath('@storybook/addon-interactions'),
getAbsolutePath('@storybook/addon-a11y'),
getAbsolutePath('@storybook/addon-webpack5-compiler-babel'),
{
name: getAbsolutePath('@storybook/addon-styling-webpack'),
options: {
rules: [
{
test: /\.css$/,
use: [
{ loader: MiniCssExtractPlugin.loader },
{ loader: 'css-loader' },
],
},
{
test: /\.less$/,
use: [
{ loader: MiniCssExtractPlugin.loader },
{ loader: 'css-loader' },
{ loader: 'less-loader' },
],
},
[web] Migrate AI Error Assistant to BS5 (#21129) * [storybook] Rerender story when switching BS3/BS5 * [storybook] Add SCSS loader to storybook * [storybook] Add some AI error assistant stories * Rename ai-error-assistant.less to .scss * Update less variables to sass * Remove duplicated selector * Replace react-bootstrap components by `OL...` * Update Checkboxes after BS5 update * Add IDs so clicking on labels work * Add BS5 class name in SCSS Note: `answer-not-detailed` is used twice in the Radios. I think it's a mistake: there should be another name for the "ai_feedback_the_suggestion_wasnt_the_best_fix_available" radio * Rename ID `answer-not-detailed` -> `answer-not-best-fix` * Pass name and value to BS3Radio/BS3Checkbox * [storybook] Add delay before AI suggestion (shows the animation) * Add a number after the checkbox/radio IDs, to allow multiple forms to be displayed Without this, clicks on second form are updating the first form! Another solution could be to wrap the input in the label, but it comes with other problems. See https://css-tricks.com/html-inputs-and-labels-a-love-story/ * [storybook] Update `LabsAiPromoBanner` * Use CSS variables instead of hardcoded values * Make radio input flex * Replace `blue-10` by `bg-info-03` * Fix `SuggestFixButton` * Fix `AiErrorAssistantCopyCode` * Fix button loading in BS5 * Use OLBadge * Fix Button variants * Update `suggestFixAction` * Migrate Tooltip and Button to BS5 in LabsExperimentWidget * Update BS3/BS5 button classname in AiErrorAssistantCopyCode Co-authored-by: Rebeka <rebeka.dekany@overleaf.com> * [storybook] Allow to choose props of `LabsExperimentWidget` * Fixup `OLTooltip`: Display the tooltip on disabled button in BS5 * Update Tooltips to BS5 --------- Co-authored-by: Rebeka <rebeka.dekany@overleaf.com> GitOrigin-RevId: 08d594e772c0a3b6db1c6081337cc2d079f478a5
2024-10-23 03:33:56 -04:00
{
// Pass Sass files through sass-loader/css-loader/mini-css-extract-
// plugin (note: run in reverse order)
test: /\.s[ac]ss$/,
use: [
// Allows the CSS to be extracted to a separate .css file
{ loader: MiniCssExtractPlugin.loader },
// Resolves any CSS dependencies (e.g. url())
{ loader: 'css-loader' },
// Resolve relative paths sensibly in SASS
{ loader: 'resolve-url-loader' },
{
// Runs autoprefixer on CSS via postcss
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: ['autoprefixer'],
},
},
},
// Compiles Sass to CSS
{
loader: 'sass-loader',
options: { sourceMap: true }, // sourceMap: true is required for resolve-url-loader
},
],
},
],
plugins: [new MiniCssExtractPlugin()],
},
},
],
framework: {
name: getAbsolutePath('@storybook/react-webpack5'),
options: {},
},
docs: {
autodocs: 'tag',
},
babel: (options: Record<string, any>) => {
return {
...options,
plugins: [
// ensure that TSX files are transformed before other plugins run
['@babel/plugin-transform-typescript', { isTSX: true }],
...(options.plugins ?? []),
],
}
},
webpackFinal: storybookConfig => {
return {
...storybookConfig,
resolve: {
...storybookConfig.resolve,
fallback: {
...storybookConfig.resolve?.fallback,
fs: false,
os: false,
module: false,
tty: require.resolve('tty-browserify'),
},
extensions: ['.js', '.jsx', '.mjs', '.ts', '.tsx', '.json'],
alias: {
...storybookConfig.resolve?.alias,
// custom prefixes for import paths
'@': path.join(rootDir, 'frontend/js/'),
},
},
module: {
...storybookConfig.module,
rules: (storybookConfig.module?.rules ?? []).concat({
test: /\.wasm$/,
type: 'asset/resource',
generator: {
filename: 'js/[name]-[contenthash][ext]',
},
}),
},
}
},
}
export default config