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>
|
||||
let className = undefined;
|
||||
export { className as class };
|
||||
export let code = undefined;
|
||||
export let copyButtonDescription = undefined;
|
||||
export let copyLabel = undefined;
|
||||
export let feedback = undefined;
|
||||
export let feedbackTimeout = undefined;
|
||||
export let id = Math.random();
|
||||
export let light = false;
|
||||
export let showLessText = 'Show less';
|
||||
export let showMoreText = 'Show more';
|
||||
|
@ -18,7 +20,6 @@
|
|||
import Copy from '../Copy';
|
||||
import CopyButton from '../CopyButton';
|
||||
|
||||
const id = Math.random();
|
||||
let codeRef = undefined;
|
||||
let expanded = false;
|
||||
let showMoreLess = false;
|
||||
|
@ -34,21 +35,20 @@
|
|||
<Copy
|
||||
aria-label={$$props['aria-label'] || copyLabel}
|
||||
aria-describedby={id}
|
||||
class={cx('--snippet', type && `--snippet--${type}`, type === 'inline' && '--btn--copy', expanded && '--snippet--expand', light && '--snippet--light', className)}
|
||||
on:click
|
||||
on:mouseover
|
||||
on:mouseenter
|
||||
on:mouseleave
|
||||
class={cx('--snippet', type && `--snippet--${type}`, type === 'inline' && '--btn--copy', expanded && '--snippet--expand', light && '--snippet--light', className)}
|
||||
{feedback}
|
||||
{feedbackTimeout}
|
||||
{style}>
|
||||
<code {id}>
|
||||
<slot />
|
||||
<slot>{code}</slot>
|
||||
</code>
|
||||
</Copy>
|
||||
{:else}
|
||||
<div
|
||||
on:click
|
||||
on:mouseover
|
||||
on:mouseenter
|
||||
on:mouseleave
|
||||
|
@ -61,16 +61,16 @@
|
|||
aria-label={$$props['aria-label'] || copyLabel || 'code-snippet'}>
|
||||
<code>
|
||||
<pre bind:this={codeRef}>
|
||||
<slot />
|
||||
<slot>{code}</slot>
|
||||
</pre>
|
||||
</code>
|
||||
</div>
|
||||
<CopyButton
|
||||
on:click
|
||||
iconDescription={copyButtonDescription}
|
||||
class={cx('--snippet-button')}
|
||||
on:click
|
||||
{feedback}
|
||||
{feedbackTimeout}
|
||||
iconDescription={copyButtonDescription} />
|
||||
{feedbackTimeout} />
|
||||
{#if showMoreLess}
|
||||
<Button
|
||||
kind="ghost"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue