diff --git a/packages/embla-carousel-docs/src/components/CodeSandbox/React/createSandboxReact.ts b/packages/embla-carousel-docs/src/components/CodeSandbox/React/createSandboxReact.ts index 3958ff00c..66cc4d51e 100644 --- a/packages/embla-carousel-docs/src/components/CodeSandbox/React/createSandboxReact.ts +++ b/packages/embla-carousel-docs/src/components/CodeSandbox/React/createSandboxReact.ts @@ -1,6 +1,7 @@ import { getParameters } from 'codesandbox/lib/api/define' import { BASE_CSS, SANDBOX_CSS } from 'components/CodeSandbox/sandboxStyles' -import { SANDBOX_IMAGES } from '../sandboxImages' +import { SANDBOX_REACT_FOLDERS } from './sandboxReactFolders' +import { createSandboxImages } from '../sandboxImages' import { loadPrettier } from 'utils/loadPrettier' import { createSandboxReactPackageJson } from './createSandboxReactPackageJson' import { createSandboxReactIndexHtml } from './createSandboxReactIndexHtml' @@ -29,6 +30,7 @@ export const createSandboxReact = async ( language = 'javascript', } = config const title = `${id}-react` + const sandboxImages = createSandboxImages(SANDBOX_REACT_FOLDERS.IMAGES) const { prettierConfig, formatCss, formatJs, formatTs } = await loadPrettier() const scriptExtension = languageToReactExtension(language) const isTypeScript = isLanguageTypeScript(language) @@ -61,39 +63,39 @@ export const createSandboxReact = async ( isBinary: false, content: JSON.stringify(packageJson, null, '\t'), }, - [`public/index.html`]: { + [`${SANDBOX_REACT_FOLDERS.PUBLIC}/index.html`]: { isBinary: false, content: entryHtml, }, - [`src/css/base.css`]: { + [`${SANDBOX_REACT_FOLDERS.CSS}/base.css`]: { isBinary: false, content: formatCss(BASE_CSS), }, - [`src/css/sandbox.css`]: { + [`${SANDBOX_REACT_FOLDERS.CSS}/sandbox.css`]: { isBinary: false, content: formatCss(SANDBOX_CSS), }, - [`src/css/embla.css`]: { + [`${SANDBOX_REACT_FOLDERS.CSS}/embla.css`]: { isBinary: false, content: formatCss(styles), }, - [`src/js/index.${scriptExtension}`]: { + [`${SANDBOX_REACT_FOLDERS.JS}/index.${scriptExtension}`]: { isBinary: false, content: formatScript(entryScript), }, - [`src/js/Header.${scriptExtension}`]: { + [`${SANDBOX_REACT_FOLDERS.JS}/Header.${scriptExtension}`]: { isBinary: false, content: formatScript(headerScript), }, - [`src/js/Footer.${scriptExtension}`]: { + [`${SANDBOX_REACT_FOLDERS.JS}/Footer.${scriptExtension}`]: { isBinary: false, content: formatScript(footerScript), }, - [`src/js/EmblaCarousel.${scriptExtension}`]: { + [`${SANDBOX_REACT_FOLDERS.JS}/EmblaCarousel.${scriptExtension}`]: { isBinary: false, content: formatScript(carouselScript), }, - [`src/js/imageByIndex.${scriptExtension}`]: { + [`${SANDBOX_REACT_FOLDERS.JS}/imageByIndex.${scriptExtension}`]: { isBinary: false, content: formatScript(imagesScript), }, @@ -113,6 +115,6 @@ export const createSandboxReact = async ( } return getParameters({ - files: Object.assign({}, sandboxConfig, SANDBOX_IMAGES, sandboxOverrides), + files: Object.assign({}, sandboxConfig, sandboxImages, sandboxOverrides), }) } diff --git a/packages/embla-carousel-docs/src/components/CodeSandbox/React/createSandboxReactPackageJson.ts b/packages/embla-carousel-docs/src/components/CodeSandbox/React/createSandboxReactPackageJson.ts index d7731fcd7..1020773c9 100644 --- a/packages/embla-carousel-docs/src/components/CodeSandbox/React/createSandboxReactPackageJson.ts +++ b/packages/embla-carousel-docs/src/components/CodeSandbox/React/createSandboxReactPackageJson.ts @@ -1,4 +1,5 @@ import docsPackageJson from 'embla-carousel-docs/package.json' +import { SANDBOX_REACT_FOLDERS } from './sandboxReactFolders' import { kebabCaseToPascalCase } from 'utils/kebabCaseToPascalCase' import { languageToReactExtension } from '../sandboxUtils' import { @@ -21,7 +22,7 @@ export const createSandboxReactPackageJson = ( version: '1.0.0', description: `${kebabCaseToPascalCase(id, ' ')} Example`, keywords: ['react', 'starter', language], - main: `src/js/index.${scriptExtension}`, + main: `${SANDBOX_REACT_FOLDERS.JS}/index.${scriptExtension}`, dependencies: { react: dependencies.react, 'react-dom': dependencies['react-dom'], diff --git a/packages/embla-carousel-docs/src/components/CodeSandbox/React/sandboxReactFolders.ts b/packages/embla-carousel-docs/src/components/CodeSandbox/React/sandboxReactFolders.ts new file mode 100644 index 000000000..88746eb83 --- /dev/null +++ b/packages/embla-carousel-docs/src/components/CodeSandbox/React/sandboxReactFolders.ts @@ -0,0 +1,6 @@ +export const SANDBOX_REACT_FOLDERS = { + PUBLIC: 'public', + CSS: 'src/css', + JS: 'src/js', + IMAGES: 'src/images', +} diff --git a/packages/embla-carousel-docs/src/components/CodeSandbox/Vanilla/SandboxFilesDist/Default/EmblaCarousel.js b/packages/embla-carousel-docs/src/components/CodeSandbox/Vanilla/SandboxFilesDist/Default/EmblaCarousel.js index 2e1535236..6ba9b0f98 100644 --- a/packages/embla-carousel-docs/src/components/CodeSandbox/Vanilla/SandboxFilesDist/Default/EmblaCarousel.js +++ b/packages/embla-carousel-docs/src/components/CodeSandbox/Vanilla/SandboxFilesDist/Default/EmblaCarousel.js @@ -1,12 +1,12 @@ -import EmblaCarousel from 'embla-carousel' -import '../css/base.css' -import '../css/sandbox.css' -import '../css/embla.css' +import EmblaCarousel from 'embla-carousel'; +import '../css/base.css'; +import '../css/sandbox.css'; +import '../css/embla.css'; -const OPTIONS = {} +const OPTIONS = {}; -const emblaNode = document.querySelector('.embla') -const viewportNode = emblaNode.querySelector('.embla__viewport') +const emblaNode = document.querySelector('.embla'); +const viewportNode = emblaNode.querySelector('.embla__viewport'); // @ts-ignore -const emblaApi = EmblaCarousel(viewportNode, OPTIONS) +const emblaApi = EmblaCarousel(viewportNode, OPTIONS); diff --git a/packages/embla-carousel-docs/src/components/CodeSandbox/Vanilla/SandboxFilesDist/index.html b/packages/embla-carousel-docs/src/components/CodeSandbox/Vanilla/SandboxFilesDist/index.html index cd83cec02..07fdddd61 100644 --- a/packages/embla-carousel-docs/src/components/CodeSandbox/Vanilla/SandboxFilesDist/index.html +++ b/packages/embla-carousel-docs/src/components/CodeSandbox/Vanilla/SandboxFilesDist/index.html @@ -37,6 +37,6 @@