mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 10:21:05 +00:00
feat(code-snippet): allow copy button to be hidden
This commit is contained in:
parent
2e980e0968
commit
029af58a1c
2 changed files with 53 additions and 25 deletions
|
@ -13,6 +13,7 @@ export const Inline = () => ({
|
||||||
"ARIA label for the snippet/copy button (copyLabel)",
|
"ARIA label for the snippet/copy button (copyLabel)",
|
||||||
"copyable code snippet"
|
"copyable code snippet"
|
||||||
),
|
),
|
||||||
|
hideCopyButton: boolean("Hide copy button (hideCopyButton", false),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -30,6 +31,7 @@ export const SingleLine = () => ({
|
||||||
"ARIA label of the container (ariaLabel)",
|
"ARIA label of the container (ariaLabel)",
|
||||||
"Container label"
|
"Container label"
|
||||||
),
|
),
|
||||||
|
hideCopyButton: boolean("Hide copy button (hideCopyButton", false),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -46,6 +48,7 @@ export const MultiLine = () => ({
|
||||||
'Text for "show less" button (showLessText)',
|
'Text for "show less" button (showLessText)',
|
||||||
"Show less"
|
"Show less"
|
||||||
),
|
),
|
||||||
|
hideCopyButton: boolean("Hide copy button (hideCopyButton", false),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,12 @@
|
||||||
*/
|
*/
|
||||||
export let expanded = false;
|
export let expanded = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set to `true` to hide the copy button
|
||||||
|
* @type {boolean} [hideCopyButton=false]
|
||||||
|
*/
|
||||||
|
export let hideCopyButton = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set to `true` to enable the light variant
|
* Set to `true` to enable the light variant
|
||||||
* @type {boolean} [light=false]
|
* @type {boolean} [light=false]
|
||||||
|
@ -108,6 +114,19 @@
|
||||||
on:mouseleave />
|
on:mouseleave />
|
||||||
{:else}
|
{:else}
|
||||||
{#if type === 'inline'}
|
{#if type === 'inline'}
|
||||||
|
{#if hideCopyButton}
|
||||||
|
<span
|
||||||
|
class="bx--snippet {type && `bx--snippet--${type}`}
|
||||||
|
{type === 'inline' && 'bx--btn--copy'}
|
||||||
|
{expanded && 'bx--snippet--expand'}
|
||||||
|
{light && 'bx--snippet--light'}
|
||||||
|
{hideCopyButton && 'bx--snippet--no-copy'}"
|
||||||
|
{...$$restProps}>
|
||||||
|
<code {id}>
|
||||||
|
<slot>{code}</slot>
|
||||||
|
</code>
|
||||||
|
</span>
|
||||||
|
{:else}
|
||||||
<Copy
|
<Copy
|
||||||
aria-label={copyLabel}
|
aria-label={copyLabel}
|
||||||
aria-describedby={id}
|
aria-describedby={id}
|
||||||
|
@ -116,7 +135,8 @@
|
||||||
class="bx--snippet {type && `bx--snippet--${type}`}
|
class="bx--snippet {type && `bx--snippet--${type}`}
|
||||||
{type === 'inline' && 'bx--btn--copy'}
|
{type === 'inline' && 'bx--btn--copy'}
|
||||||
{expanded && 'bx--snippet--expand'}
|
{expanded && 'bx--snippet--expand'}
|
||||||
{light && 'bx--snippet--light'}"
|
{light && 'bx--snippet--light'}
|
||||||
|
{hideCopyButton && 'bx--snippet--no-copy'}"
|
||||||
{...$$restProps}
|
{...$$restProps}
|
||||||
on:click
|
on:click
|
||||||
on:mouseover
|
on:mouseover
|
||||||
|
@ -126,14 +146,17 @@
|
||||||
<slot>{code}</slot>
|
<slot>{code}</slot>
|
||||||
</code>
|
</code>
|
||||||
</Copy>
|
</Copy>
|
||||||
|
{/if}
|
||||||
{:else}
|
{:else}
|
||||||
<div
|
<div
|
||||||
class:bx--snippet={true}
|
class:bx--snippet={true}
|
||||||
class={type && `bx--snippet--${type}`}
|
|
||||||
class:bx--btn--copy={type === 'inline'}
|
class:bx--btn--copy={type === 'inline'}
|
||||||
class:bx--snippet--expand={expanded}
|
class:bx--snippet--expand={expanded}
|
||||||
class:bx--snippet--light={light}
|
class:bx--snippet--light={light}
|
||||||
|
class:bx--snippet--no-copy={hideCopyButton}
|
||||||
{...$$restProps}
|
{...$$restProps}
|
||||||
|
class="{type && `bx--snippet--${type}`}
|
||||||
|
{$$restProps.class}"
|
||||||
on:mouseover
|
on:mouseover
|
||||||
on:mouseenter
|
on:mouseenter
|
||||||
on:mouseleave>
|
on:mouseleave>
|
||||||
|
@ -148,12 +171,14 @@
|
||||||
</pre>
|
</pre>
|
||||||
</code>
|
</code>
|
||||||
</div>
|
</div>
|
||||||
|
{#if !hideCopyButton}
|
||||||
<CopyButton
|
<CopyButton
|
||||||
{feedback}
|
{feedback}
|
||||||
{feedbackTimeout}
|
{feedbackTimeout}
|
||||||
iconDescription={copyButtonDescription}
|
iconDescription={copyButtonDescription}
|
||||||
on:click
|
on:click
|
||||||
on:animationend />
|
on:animationend />
|
||||||
|
{/if}
|
||||||
{#if showMoreLess}
|
{#if showMoreLess}
|
||||||
<Button
|
<Button
|
||||||
kind="ghost"
|
kind="ghost"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue