/* eslint-disable no-useless-escape */ import React from 'react'; import { storybookArgTypes, storybookExcludedControlParams, type StoryMetaType, type StoryType, } from '@lg-tools/storybook-utils'; import { css } from '@leafygreen-ui/emotion'; import { Icon } from '@leafygreen-ui/icon'; import { IconButton } from '@leafygreen-ui/icon-button'; import { LanguageSwitcherWithPanelExample } from './LanguageSwitcher/LanguageSwitcherExample'; import { languageOptions } from './testing/Code.testutils'; import { Code, CodeProps, CopyButton, CopyButtonAppearance, Language, Panel, } from '.'; const customActionButtons = [ {}} aria-label="label" key="1"> , , , ]; const jsSnippet = ` import datetime from './'; const myVar = 42; var myObj = { someProp: ['arr', 'ay'], regex: /([A-Z])\w+/ } export default class myClass { constructor(){ // access properties this.myProp = false } } function greeting(entity) { return \`Hello, \${entity}! Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper.\`; } console.log(greeting('World')); `; const jsCustomSnippet = ` mongosh "mongodb+srv://cluster0.abcde.mongodb.net/test" --api 1 --username aang mongosh "mongodb+srv://cluster0.abcde.mongodb.net/test" api 1 username aang mongosh "mongodb+srv://cluster0.abcde.mongodb.net/testing" api 1 username aang testing a line api and testing username testingalineapiandtestingusername `; // > 5 lines to trigger expandable code block const shortJsSnippet = ` function greeting(entity) { return \`Hello, \${entity}\`; } console.log(greeting('World')); console.log(greeting('Universe')); `; const meta: StoryMetaType = { title: 'Components/Display/Code', component: Code, parameters: { default: 'LiveExample', controls: { exclude: [ ...storybookExcludedControlParams, 'showCustomActionButtons', 'showCustomButtons', 'customActionButtons', 'languageOptions', 'children', 'customKeywords', ], }, generate: { storyNames: ['WithPanel', 'WithoutPanel', 'Loading'], }, }, args: { language: 'js', baseFontSize: 14, children: shortJsSnippet, copyButtonAppearance: CopyButtonAppearance.Hover, collapsedLines: 5, }, argTypes: { isLoading: { control: 'boolean' }, expandable: { control: 'boolean' }, showLineNumbers: { control: 'boolean' }, highlightLines: { control: 'boolean' }, darkMode: storybookArgTypes.darkMode, lineNumberStart: { control: 'number' }, baseFontSize: storybookArgTypes.baseFontSize, language: { options: Object.values(Language), control: { type: 'select', }, }, copyButtonAppearance: { options: Object.values(CopyButtonAppearance), control: { type: 'select', }, }, collapsedLines: { control: 'number' }, }, }; export default meta; type BaseFontSize = 14 | 16; interface FontSizeProps { baseFontSize: BaseFontSize; } export const LiveExample: StoryType = ({ highlightLines, ...args }: CodeProps & FontSizeProps) => ( {jsSnippet} ); LiveExample.parameters = { chromatic: { disableSnapshot: true, }, }; LiveExample.parameters = { chromatic: { disableSnapshot: true, }, }; export const Collapsed: StoryType = ({ highlightLines, ...args }: CodeProps & FontSizeProps) => ( {jsSnippet} ); export const CustomWord: StoryType = ({ baseFontSize, highlightLines, ...args }: CodeProps & FontSizeProps) => (
      customKeywords={' '}
      {JSON.stringify(
        {
          testing: 'custom',
          api: 'custom',
          username: 'custom',
        },
        null,
        2,
      )}
    


{jsCustomSnippet}
); export const WithCustomActions: StoryType = ({ highlightLines, ...args }: CodeProps & FontSizeProps) => ( } > {jsSnippet} ); export const WithLanguageSwitcher: StoryType = ({ ...args }: CodeProps & FontSizeProps) => ( ); WithLanguageSwitcher.parameters = { controls: { exclude: [ 'highlightLines', 'copyButtonAppearance', 'children', 'expandable', ], }, }; export const Multiple: StoryType = ({ highlightLines, ...args }: CodeProps & FontSizeProps) => (
{jsSnippet}
{jsCustomSnippet}
); export const WithPanel = () => {}; WithPanel.parameters = { generate: { combineArgs: { darkMode: [false, true], expandable: [true, false], showLineNumbers: [false, true], highlightLines: [[], [2]], language: ['js', languageOptions[0].displayName], panel: [ , , {}} key={3} />, {}} key={4} />, , , {}} key={7} />, ], }, excludeCombinations: [ { language: 'js', panel: , }, ], }, }; export const WithoutPanel: StoryType = () => <>; WithoutPanel.parameters = { generate: { args: { language: languageOptions[0].displayName, }, combineArgs: { // @ts-expect-error - data-hover is not a valid prop 'data-hover': [false, true], darkMode: [false, true], expandable: [true, false], highlightLines: [[], [2]], copyButtonAppearance: [ CopyButtonAppearance.Hover, CopyButtonAppearance.Persist, ], showLineNumbers: [false, true], }, excludeCombinations: [ { // @ts-expect-error - data-hover is not a valid prop ['data-hover']: true, copyButtonAppearance: CopyButtonAppearance.Persist, }, ], }, }; export const Loading = () => {}; Loading.parameters = { chromatic: { viewports: [1500] }, controls: { exclude: /.*/g, }, generate: { combineArgs: { darkMode: [false, true], expandable: [true, false], panel: [ undefined, {}} key={7} />, ], }, args: { language: languageOptions[0].displayName, isLoading: true, }, decorator: Instance => { return (
); }, }, }; export const CopyButtonExample = () => { return ; };