mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 02:11:05 +00:00
feat(code-snippet): support code prop
This commit is contained in:
parent
37e2855c83
commit
a5e98de4a7
1 changed files with 8 additions and 8 deletions
|
@ -1,10 +1,12 @@
|
||||||
<script>
|
<script>
|
||||||
let className = undefined;
|
let className = undefined;
|
||||||
export { className as class };
|
export { className as class };
|
||||||
|
export let code = undefined;
|
||||||
export let copyButtonDescription = undefined;
|
export let copyButtonDescription = undefined;
|
||||||
export let copyLabel = undefined;
|
export let copyLabel = undefined;
|
||||||
export let feedback = undefined;
|
export let feedback = undefined;
|
||||||
export let feedbackTimeout = undefined;
|
export let feedbackTimeout = undefined;
|
||||||
|
export let id = Math.random();
|
||||||
export let light = false;
|
export let light = false;
|
||||||
export let showLessText = 'Show less';
|
export let showLessText = 'Show less';
|
||||||
export let showMoreText = 'Show more';
|
export let showMoreText = 'Show more';
|
||||||
|
@ -18,7 +20,6 @@
|
||||||
import Copy from '../Copy';
|
import Copy from '../Copy';
|
||||||
import CopyButton from '../CopyButton';
|
import CopyButton from '../CopyButton';
|
||||||
|
|
||||||
const id = Math.random();
|
|
||||||
let codeRef = undefined;
|
let codeRef = undefined;
|
||||||
let expanded = false;
|
let expanded = false;
|
||||||
let showMoreLess = false;
|
let showMoreLess = false;
|
||||||
|
@ -34,21 +35,20 @@
|
||||||
<Copy
|
<Copy
|
||||||
aria-label={$$props['aria-label'] || copyLabel}
|
aria-label={$$props['aria-label'] || copyLabel}
|
||||||
aria-describedby={id}
|
aria-describedby={id}
|
||||||
|
class={cx('--snippet', type && `--snippet--${type}`, type === 'inline' && '--btn--copy', expanded && '--snippet--expand', light && '--snippet--light', className)}
|
||||||
on:click
|
on:click
|
||||||
on:mouseover
|
on:mouseover
|
||||||
on:mouseenter
|
on:mouseenter
|
||||||
on:mouseleave
|
on:mouseleave
|
||||||
class={cx('--snippet', type && `--snippet--${type}`, type === 'inline' && '--btn--copy', expanded && '--snippet--expand', light && '--snippet--light', className)}
|
|
||||||
{feedback}
|
{feedback}
|
||||||
{feedbackTimeout}
|
{feedbackTimeout}
|
||||||
{style}>
|
{style}>
|
||||||
<code {id}>
|
<code {id}>
|
||||||
<slot />
|
<slot>{code}</slot>
|
||||||
</code>
|
</code>
|
||||||
</Copy>
|
</Copy>
|
||||||
{:else}
|
{:else}
|
||||||
<div
|
<div
|
||||||
on:click
|
|
||||||
on:mouseover
|
on:mouseover
|
||||||
on:mouseenter
|
on:mouseenter
|
||||||
on:mouseleave
|
on:mouseleave
|
||||||
|
@ -61,16 +61,16 @@
|
||||||
aria-label={$$props['aria-label'] || copyLabel || 'code-snippet'}>
|
aria-label={$$props['aria-label'] || copyLabel || 'code-snippet'}>
|
||||||
<code>
|
<code>
|
||||||
<pre bind:this={codeRef}>
|
<pre bind:this={codeRef}>
|
||||||
<slot />
|
<slot>{code}</slot>
|
||||||
</pre>
|
</pre>
|
||||||
</code>
|
</code>
|
||||||
</div>
|
</div>
|
||||||
<CopyButton
|
<CopyButton
|
||||||
on:click
|
iconDescription={copyButtonDescription}
|
||||||
class={cx('--snippet-button')}
|
class={cx('--snippet-button')}
|
||||||
|
on:click
|
||||||
{feedback}
|
{feedback}
|
||||||
{feedbackTimeout}
|
{feedbackTimeout} />
|
||||||
iconDescription={copyButtonDescription} />
|
|
||||||
{#if showMoreLess}
|
{#if showMoreLess}
|
||||||
<Button
|
<Button
|
||||||
kind="ghost"
|
kind="ghost"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue