Skip to content

Commit

Permalink
fix(storybook): intro mdx files now load
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnacioBecerra committed Dec 19, 2023
1 parent 0b572ea commit f12f744
Show file tree
Hide file tree
Showing 11 changed files with 252 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>
<head>
<script
type="module"
src="https://1.www.s81c.com/common/carbon/web-components/tag/v2/canary/dropdown.min.js"></script>
<style type="text/css">
#app {
font-family: 'IBM Plex Sans', 'Helvetica Neue', Arial, sans-serif;
width: 300px;
margin: 2rem;
}

cds-dropdown:not(:defined),
cds-dropdown-item:not(:defined) {
visibility: hidden;
}
</style>
</head>
<body>
<div id="app">
<cds-dropdown trigger-content="Select an item">
<cds-dropdown-item value="all">Option 1</cds-dropdown-item>
<cds-dropdown-item value="cloudFoundry">Option 2</cds-dropdown-item>
<cds-dropdown-item value="staging">Option 3</cds-dropdown-item>
<cds-dropdown-item value="dea">Option 4</cds-dropdown-item>
<cds-dropdown-item value="router">Option 5</cds-dropdown-item>
</cds-dropdown>
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ import { mergeConfig } from 'vite';
import { litStyleLoader, litTemplateLoader } from '@mordech/vite-lit-loader';
import viteSVGResultCarbonIconLoader from '../tools/vite-svg-result-carbon-icon-loader';
const glob = require('fast-glob');
import remarkGfm from 'remark-gfm';


const stories = glob
.sync(['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'], {
.sync(['../src/**/*.mdx', '../docs/**/*.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'], {
ignore: ['../src/**/docs/*.mdx'],
cwd: __dirname,
})

const config: StorybookConfig = {
const config: StorybookConfig = {
stories: stories,
addons: [
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/addon-mdx-gfm',
],
framework: {
name: '@storybook/web-components-vite',
Expand All @@ -32,6 +34,7 @@ const stories = glob
// alias: {
// '@carbon/web-components/es/icons': path.resolve(__dirname, '@carbon/icons/lib') },
// },
assetsInclude: ['**/*.html'],
plugins: [litStyleLoader(), litTemplateLoader(), viteSVGResultCarbonIconLoader()],
optimizeDeps: {
include: ['@storybook/web-components'],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Copyright IBM Corp. 2020, 2022
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import { addons } from '@storybook/addons';
import yourTheme from './theme';

addons.setConfig({
theme: yourTheme,
});

/**
* Conditionally generate CSS to hide a component based on its corresponding
* feature flag environment variable.
*
* @param {*} envVar
* Environment variable to check.
* @param {*} cssId
* CSS ID for selector.
* @returns
*/
const getCss = (envVar, cssId) => {
return envVar !== 'true'
? `button[id^="${cssId}"] { display: none !important; }\n`
: '';
};

// Build string of CSS rules.
let css = '';
if (!process.env.CDS_FLAGS_ALL) {
css += getCss(
process.env.CDS_EXPERIEMENTAL_COMPONENT_NAME,
'components-experimental-component-name'
);
}

// Inject any CSS rules into the page.
if (css.length) {
const head = document.head || document.getElementsByTagName('head')[0];
const style = document.createElement('style');
head.appendChild(style);
style.appendChild(document.createTextNode(css));
}
168 changes: 162 additions & 6 deletions web-components/packages/carbon-web-components/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,181 @@
import { setCustomElementsManifest } from '@storybook/web-components';
import customElements from '../custom-elements.json';
import container from './container';
import { white, g10, g90, g100 } from '@carbon/themes';
import { breakpoints } from '@carbon/layout';
import theme from './theme';


setCustomElementsManifest(customElements);

// export const Preview = {
// parameters: {
// controls: { expanded: true },
// },
// };
export const globalTypes = {
locale: {
name: 'Locale',
description: 'Set the localization for the storybook',
defaultValue: 'en',
toolbar: {
icon: 'globe',
items: [
{
right: '🇺🇸',
title: 'English',
value: 'en',
},
{
right: '🇵🇸',
title: 'Arabic',
value: 'ar',
},
],
},
},
dir: {
name: 'Text direction',
description: 'Set the text direction for the story',
defaultValue: 'ltr',
toolbar: {
icon: 'transfer',
title: 'Text direction',
items: [
{
right: '🔄',
title: 'auto',
value: 'auto',
},
{
right: '➡️',
title: 'left-to-right (ltr)',
value: 'ltr',
},
{
right: '⬅️',
title: 'right-to-left (rtl)',
value: 'rtl',
},
],
},
},
theme: {
name: 'Theme',
description: 'Set the global theme for displaying components',
defaultValue: 'white',
toolbar: {
icon: 'paintbrush',
title: 'Theme',
items: ['white', 'g10', 'g90', 'g100'],
},
}
};

export const parameters = {
backgrounds: {
// https://storybook.js.org/docs/react/essentials/backgrounds#grid
grid: {
cellSize: 8,
opacity: 0.5,
},
values: [
{
name: 'white',
value: white.background,
},
{
name: 'g10',
value: g10.background,
},
{
name: 'g90',
value: g90.background,
},
{
name: 'g100',
value: g100.background,
},
],
},
controls: {
expanded: true,
sort: 'alpha',

hideNoControlsWarning: true,
},
docs: {
theme,
},
viewport: {
viewports: {
sm: {
name: 'Small',
styles: {
width: breakpoints.sm.width,
height: '100%',
},
},
md: {
name: 'Medium',
styles: {
width: breakpoints.md.width,
height: '100%',
},
},
lg: {
name: 'Large',
styles: {
width: breakpoints.lg.width,
height: '100%',
},
},
xlg: {
name: 'X-Large',
styles: {
width: breakpoints.xlg.width,
height: '100%',
},
},
Max: {
name: 'Max',
styles: {
width: breakpoints.max.width,
height: '100%',
},
},
},
},
options: {
storySort: {
order: [
'Introduction',
[
'Welcome',
'Custom styles',
'Carbon CDN style helpers',
'Form Participation',
],
'Components',
'Layout',
],
},
},
}

export const decorators = [
function decoratorContainer(story, context) {
const result = story();
const { hasMainTag } = result;
const { theme } = context.globals;
const { locale, dir, theme } = context.globals;


document.documentElement.setAttribute('storybook-carbon-theme', theme);

document.documentElement.lang = locale;
document.documentElement.dir = dir;

return container({ hasMainTag, children: result });
},
];

export const Preview = {
parameters,
globalTypes,
decorators
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* LICENSE file in the root directory of this source tree.
*/

import { create } from '@storybook/theming';
import { create } from '@storybook/theming/create';
import { version } from '../package.json';

export default create({
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Description, Meta } from '@storybook/addon-docs/blocks';

<Meta title="Introduction/Carbon CDN style helpers" />

# Carbon CDN Style Helpers
<!-- prettier-ignore-start -->
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

## Table of contents

- [Overview](#overview)
Expand All @@ -11,8 +13,6 @@
- [Available classes](#available-classes)
- [Example usage](#example-usage)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->
<!-- prettier-ignore-end -->

## Overview

Expand Down Expand Up @@ -326,3 +326,4 @@ in Carbon.
</body>
</html>
```

1 change: 1 addition & 0 deletions web-components/packages/carbon-web-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
"@storybook/addon-essentials": "^7.6.4",
"@storybook/addon-knobs": "^7.0.2",
"@storybook/addon-links": "^7.6.4",
"@storybook/addon-mdx-gfm": "^7.6.5",
"@storybook/addon-storysource": "^7.6.4",
"@storybook/blocks": "^7.6.4",
"@storybook/web-components": "^7.6.4",
Expand Down

0 comments on commit f12f744

Please sign in to comment.