Make wraps a passable prop to EditorToolbar

Can be set to nowrap via document.getElementByID("editorToolbar").component.$set({ wraps: false })
This commit is contained in:
Henrik Giesel 2021-04-08 17:26:30 +02:00
parent bf33397855
commit 59884df70b
3 changed files with 15 additions and 7 deletions

View file

@ -6,13 +6,12 @@
export let props: Record<string, string> = {};
export let buttons: Buttons;
export let wraps: boolean;
</script>
<style lang="scss">
ul {
display: flex;
/* flex-flow: nowrap for a scrollable toolbar */
flex-flow: wrap;
overflow-y: auto;
padding-inline-start: 0;
@ -24,6 +23,10 @@
}
}
.wraps {
flex-flow: wrap;
}
li {
display: inline-block;
margin-bottom: calc(var(--toolbar-size) / 15);
@ -51,11 +54,11 @@
}
</style>
<ul {id} class={className} {...props}>
<ul {id} class={className} {...props} class:wraps>
{#each buttons as button}
<li>
{#if Array.isArray(button)}
<svelte:self buttons={button} />
<svelte:self buttons={button} {wraps} />
{:else}
<svelte:component this={button.component} {...button} />
{/if}

View file

@ -29,6 +29,7 @@
export let nightMode: boolean;
export let size: number = 30;
export let wraps: boolean = true;
setContext(nightModeKey, nightMode);
setContext(disabledKey, disabled);
@ -65,6 +66,6 @@
</div>
<nav>
<ButtonGroup buttons={_buttons} />
<ButtonGroup buttons={_buttons} {wraps} />
</nav>
</div>

View file

@ -6,12 +6,16 @@ export interface DynamicSvelteComponent<
component: T;
}
export const dynamicComponent = <Comp extends typeof SvelteComponentDev>(component: Comp) => <
export const dynamicComponent = <Comp extends typeof SvelteComponentDev>(
component: Comp
) => <
Props extends NonNullable<ConstructorParameters<Comp>[0]["props"]>,
Lazy extends string = never
>(
props: Omit<Props, Lazy>,
lazyProps: { [Property in keyof Pick<Props, Lazy>]: () => Pick<Props, Lazy>[Property] }
lazyProps: {
[Property in keyof Pick<Props, Lazy>]: () => Pick<Props, Lazy>[Property];
}
): DynamicSvelteComponent<Comp> & Props => {
const dynamicComponent = { component, ...props };