mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 18:31:06 +00:00
refactor(code-snippet): pass snippet button class for multi-line
- Remove exported props from CopyButton, skeleton - Replace onMount with reactive statement - Forward events to skeleton - Clean up Story
This commit is contained in:
parent
5ca9f35286
commit
40a7be5c79
3 changed files with 23 additions and 26 deletions
|
@ -10,7 +10,6 @@
|
|||
export let light = false;
|
||||
export let props = {};
|
||||
|
||||
import { onMount } from 'svelte';
|
||||
import ChevronDown16 from 'carbon-icons-svelte/lib/ChevronDown16';
|
||||
import { cx } from '../../lib';
|
||||
import Button from '../Button';
|
||||
|
@ -20,18 +19,16 @@
|
|||
const id = Math.random();
|
||||
let codeRef = undefined;
|
||||
let expandedCode = false;
|
||||
let shouldShowMoreLessBtn = false;
|
||||
|
||||
onMount(() => {
|
||||
if (codeRef) {
|
||||
const { height } = codeRef.getBoundingClientRect();
|
||||
shouldShowMoreLessBtn = type === 'multi' && height > 255;
|
||||
}
|
||||
});
|
||||
let showMoreLessBtn = false;
|
||||
|
||||
$: if (codeRef) {
|
||||
const { height } = codeRef.getBoundingClientRect();
|
||||
showMoreLessBtn = type === 'multi' && height > 255;
|
||||
}
|
||||
$: _class = cx(
|
||||
'--snippet',
|
||||
type && `--snippet--${type}`,
|
||||
type === 'inline' && '--btn--copy',
|
||||
expandedCode && '--snippet--expand',
|
||||
light && '--snippet--light',
|
||||
className
|
||||
|
@ -64,8 +61,12 @@
|
|||
</pre>
|
||||
</code>
|
||||
</div>
|
||||
<CopyButton on:click {feedback} iconDescription={copyButtonDescription} />
|
||||
{#if shouldShowMoreLessBtn}
|
||||
<CopyButton
|
||||
on:click
|
||||
class={cx('--snippet-button')}
|
||||
{feedback}
|
||||
iconDescription={copyButtonDescription} />
|
||||
{#if showMoreLessBtn}
|
||||
<Button
|
||||
kind="ghost"
|
||||
size="small"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue