Skip to content

Commit

Permalink
Improve interactive examples
Browse files Browse the repository at this point in the history
  • Loading branch information
clauderic committed Nov 10, 2024
1 parent 4b97ec4 commit f599bfb
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 26 deletions.
10 changes: 3 additions & 7 deletions apps/docs/react/hooks/use-draggable.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@ icon: 'bullseye-pointer'
import {Story} from '/snippets/story.mdx';
import {CodeSandbox} from '/snippets/code.mdx';

<Story id="react-draggable--example" height="125" hero />

## Usage

The `useDraggable` hook requires an `id` and accepts all the same options as the `Draggable` class. Refer to the [Input](#input) section below for more information.

<CodeSandbox files={{
'App.js': {code: app, hidden: true},
'Draggable.js': {code, active: true},
'styles.css': {code: styles, hidden: true},
}} height={220} previewHeight={140} />
}} height={220} previewHeight={200} hero />

The `useDraggable` hook requires an `id` and accepts all the same options as the `Draggable` class. Refer to the [Input](#input) section below for more information.

## API Reference

Expand Down
18 changes: 1 addition & 17 deletions apps/docs/sandpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,6 @@ class SandpackElement extends HTMLElement {
files = JSON.parse(this.getAttribute("files"));
} catch {}
const styles = files['styles.css'];
const backgroundColor = document.documentElement.classList.contains('dark')
? '#11131b'
: '#fafafd';
if (styles) {
const background = \`html {background-color: \${backgroundColor};}\`;
files['styles.css'] = typeof styles == 'string' ? {
code: \`\${background} \${styles}\`,
} : {
...styles,
code: \`\${background} \${styles.code}\`,
};
}
const sandpackComponent = React.createElement(Sandpack, {
files,
template: "react",
Expand All @@ -107,7 +91,7 @@ class SandpackElement extends HTMLElement {
}
customElements.define("code-sandbox", SandpackElement);
`.replace(/\n/g, ' ');
`;

script.type = 'module';
script.innerText = code;
Expand Down
4 changes: 2 additions & 2 deletions apps/docs/snippets/code.mdx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export const CodeSandbox = ({ files, height, previewHeight, showTabs }) => {
export const CodeSandbox = ({ files, height, previewHeight, showTabs, hero }) => {
const Element = 'code-sandbox';

return (
<Element
class="not-prose"
class={`not-prose${hero ? ' hero' : ''}`}
files={JSON.stringify(files)}
height={height}
style={previewHeight ? {'--preview-height': `${previewHeight}px`} : undefined}
Expand Down
67 changes: 67 additions & 0 deletions apps/docs/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ kbd {
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
}

html:not(.dark) .hero .sp-layout {
box-shadow: none;
}


.sp-tabs-scrollable-container {
padding-left: 0;
padding-right: 0;
Expand All @@ -131,6 +136,10 @@ kbd {
border-color: rgb(var(--primary-light));
}

.sp-layout {
gap: 0px;
}

.dark .sp-layout {
--tw-ring-color: rgb(var(--gray-800) / 0.5);
}
Expand All @@ -140,6 +149,10 @@ kbd {
order: 1;
}

.sp-preview {
flex-basis: 100% !important;
}

.sp-preview, .sp-preview-container {
background-color: transparent;
}
Expand All @@ -151,3 +164,57 @@ kbd {
code-sandbox[style*="--preview-height"] .sp-preview {
height: var(--preview-height) !important;
}

.sp-preview-container, .sp-overlay {
background-color: #fafafd;
}

.dark .sp-preview-container, .dark .sp-overlay {
background-color: #11131b;
}

.sp-preview-container iframe {
background: transparent;
color-scheme: normal;
}

.hero .sp-preview-container, .hero .sp-overlay {
--gradient: linear-gradient(65deg, #56fff420, #001AFF20, #5F6AF220, #F25FD020, #56FFF520, #F25FD020, #001AFF20, #56fff420);
background-image: var(--gradient);
animation: background 16s linear infinite;
animation-direction: alternate;
background-size: 600% 100%;
}

.dark .hero .sp-preview-container, .dark .hero .sp-overlay {
--gradient: linear-gradient(65deg, #56fff480, #001AFF80, #5F6AF280, #F25FD080, #56FFF580, #F25FD080, #001AFF80, #56fff480);
animation: gradient 16s linear infinite;
}


@keyframes gradient {
0% {
background-color: #ff0000;
}
25% {
background-color: #7f00ff;
}
50% {
background-color: #00affa;
}
75% {
background-color: #00f594;
}
100% {
background-color: #ff0000
}
}

@keyframes background-position {
0% {
background-position: 0% 50%;
}
100% {
background-position: 100% 50%;
}
}

0 comments on commit f599bfb

Please sign in to comment.