Skip to content

Commit

Permalink
Merge pull request #18888 from storybookjs/pocka/fix/18829-outdated-s…
Browse files Browse the repository at this point in the history
…nippet-copied

Fix copy button copying outdated snippet
  • Loading branch information
ndelangen authored Sep 13, 2022
2 parents cb19030 + 191103a commit ae61864
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion code/frameworks/vue3-vite/preset.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
console.log('vue3-vite preset!')
console.log('vue3-vite preset!');
module.exports = require('./dist/preset');
7 changes: 3 additions & 4 deletions code/lib/builder-manager/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ export interface Stats {
toJson: () => any;
}

export type WithRequiredProperty<Type, Key extends keyof Type> = Type &
{
[Property in Key]-?: Type[Property];
};
export type WithRequiredProperty<Type, Key extends keyof Type> = Type & {
[Property in Key]-?: Type[Property];
};

export type ManagerBuilder = Builder<
WithRequiredProperty<BuildOptions, 'outdir'> & { entryPoints: string[] },
Expand Down
4 changes: 3 additions & 1 deletion code/lib/builder-vite/src/codegen-entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import type { ExtendedOptions } from './types';
import { listStories } from './list-stories';

const absoluteFilesToImport = (files: string[], name: string) =>
files.map((el, i) => `import ${name ? `* as ${name}_${i} from ` : ''}'/@fs/${normalizePath(el)}'`).join('\n');
files
.map((el, i) => `import ${name ? `* as ${name}_${i} from ` : ''}'/@fs/${normalizePath(el)}'`)
.join('\n');

export async function generateVirtualStoryEntryCode(options: ExtendedOptions) {
const storyEntries = await listStories(options);
Expand Down
21 changes: 12 additions & 9 deletions code/lib/components/src/syntaxhighlighter/syntaxhighlighter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,18 @@ export const SyntaxHighlighter: FC<SyntaxHighlighterProps> = ({
const highlightableCode = formatter ? formatter(format, children) : children.trim();
const [copied, setCopied] = useState(false);

const onClick = useCallback((e: MouseEvent<HTMLButtonElement>) => {
e.preventDefault();
copyToClipboard(highlightableCode)
.then(() => {
setCopied(true);
globalWindow.setTimeout(() => setCopied(false), 1500);
})
.catch(logger.error);
}, []);
const onClick = useCallback(
(e: MouseEvent<HTMLButtonElement>) => {
e.preventDefault();
copyToClipboard(highlightableCode)
.then(() => {
setCopied(true);
globalWindow.setTimeout(() => setCopied(false), 1500);
})
.catch(logger.error);
},
[highlightableCode]
);
const renderer = wrapRenderer(rest.renderer, showLineNumbers);

return (
Expand Down

0 comments on commit ae61864

Please sign in to comment.