From 84ea2351fb4290f544e990a0f7462645689a9130 Mon Sep 17 00:00:00 2001 From: Samuel Janda Date: Sun, 14 Jan 2024 18:02:51 +1100 Subject: [PATCH] Added slots for Standardize props and events #1621 --- COMPONENT_INDEX.md | 38 ++++++++++++++------------- docs/src/COMPONENT_API.json | 27 ++++++++++++++++--- src/TextInput/TextInput.svelte | 16 ++++++++--- types/TextInput/TextInput.svelte.d.ts | 8 +++--- 4 files changed, 60 insertions(+), 29 deletions(-) diff --git a/COMPONENT_INDEX.md b/COMPONENT_INDEX.md index 7e3a18d0..dc4af73d 100644 --- a/COMPONENT_INDEX.md +++ b/COMPONENT_INDEX.md @@ -4219,7 +4219,7 @@ None. | :-------------- | :------- | :--------------- | :------- | --------------------------------------------- | ------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | value | No | let | Yes | null | number | string | "" | Specify the input value
`value` will be set to `null` if `type = "number"` and the value is empty | | ref | No | let | Yes | null | HTMLInputElement | null | Obtain a reference to the input HTML element | -| counter | No | let | No | -- | undefined | Set to "char" to enable display the character counter or "word" to display the word count. | +| counter | No | let | No | "char" | "word" | undefined | Set to "char" to enable display the character counter or "word" to display the word count. | | disabled | No | let | No | boolean | false | Set to `true` to disable the input | | helperText | No | let | No | string | "" | Specify the helper text | | hideLabel | No | let | No | boolean | false | Set to `true` to visually hide the label text | @@ -4242,26 +4242,28 @@ None. ### Slots -| Slot name | Default | Props | Fallback | -| :--------- | :------ | :---- | :------------------------ | -| helperText | No | -- | {helperText} | -| labelText | No | -- | {labelText} | +| Slot name | Default | Props | Fallback | +| :---------- | :------ | :---- | :------------------------- | +| helperText | No | -- | {helperText} | +| invalidText | No | -- | {invalidText} | +| labelText | No | -- | {labelText} | +| warnText | No | -- | {warnText} | ### Events -| Event name | Type | Detail | -| :--------- | :--------- | :----- | -| click | forwarded | -- | -| mouseover | forwarded | -- | -| mouseenter | forwarded | -- | -| mouseleave | forwarded | -- | -| keydown | forwarded | -- | -| keyup | forwarded | -- | -| focus | forwarded | -- | -| blur | forwarded | -- | -| paste | forwarded | -- | -| input | dispatched | -- | -| change | dispatched | -- | +| Event name | Type | Detail | +| :--------- | :--------- | :-------------------------------------------- | +| change | dispatched | null | number | string | +| input | dispatched | null | number | string | +| click | forwarded | -- | +| mouseover | forwarded | -- | +| mouseenter | forwarded | -- | +| mouseleave | forwarded | -- | +| keydown | forwarded | -- | +| keyup | forwarded | -- | +| focus | forwarded | -- | +| blur | forwarded | -- | +| paste | forwarded | -- | ## `TextInputSkeleton` diff --git a/docs/src/COMPONENT_API.json b/docs/src/COMPONENT_API.json index fc6a873a..d06ad877 100644 --- a/docs/src/COMPONENT_API.json +++ b/docs/src/COMPONENT_API.json @@ -12701,6 +12701,7 @@ "name": "counter", "kind": "let", "description": "Set to \"char\" to enable display the character counter or \"word\" to display the word count.", + "type": "\"char\" | \"word\"", "isFunction": false, "isFunctionDeclaration": false, "isRequired": false, @@ -12965,14 +12966,36 @@ "fallback": "{helperText}", "slot_props": "{}" }, + { + "name": "invalidText", + "default": false, + "fallback": "{invalidText}", + "slot_props": "{}" + }, { "name": "labelText", "default": false, "fallback": "{labelText}", "slot_props": "{}" + }, + { + "name": "warnText", + "default": false, + "fallback": "{warnText}", + "slot_props": "{}" } ], "events": [ + { + "type": "dispatched", + "name": "change", + "detail": "null | number | string" + }, + { + "type": "dispatched", + "name": "input", + "detail": "null | number | string" + }, { "type": "forwarded", "name": "click", "element": "div" }, { "type": "forwarded", "name": "mouseover", "element": "div" }, { "type": "forwarded", "name": "mouseenter", "element": "div" }, @@ -12981,9 +13004,7 @@ { "type": "forwarded", "name": "keyup", "element": "input" }, { "type": "forwarded", "name": "focus", "element": "input" }, { "type": "forwarded", "name": "blur", "element": "input" }, - { "type": "forwarded", "name": "paste", "element": "input" }, - { "type": "dispatched", "name": "input" }, - { "type": "dispatched", "name": "change" } + { "type": "forwarded", "name": "paste", "element": "input" } ], "typedefs": [] }, diff --git a/src/TextInput/TextInput.svelte b/src/TextInput/TextInput.svelte index 42f316ce..2912dfce 100644 --- a/src/TextInput/TextInput.svelte +++ b/src/TextInput/TextInput.svelte @@ -293,11 +293,15 @@ {/if} {#if isFluid && !inline && invalid}
- {invalidText} + + {invalidText} +
{/if} {#if isFluid && !inline && warn} -
{warnText}
+
+ {warnText} +
{/if} {#if !invalid && !warn && !isFluid && !inline && (helperText || $$slots.helperText)} @@ -314,11 +318,15 @@ {/if} {#if !isFluid && invalid}
- {invalidText} + + {invalidText} +
{/if} {#if !isFluid && !invalid && warn} -
{warnText}
+
+ {warnText} +
{/if} diff --git a/types/TextInput/TextInput.svelte.d.ts b/types/TextInput/TextInput.svelte.d.ts index bb5c7781..ea98cb88 100644 --- a/types/TextInput/TextInput.svelte.d.ts +++ b/types/TextInput/TextInput.svelte.d.ts @@ -5,7 +5,7 @@ export interface TextInputProps { * Set to "char" to enable display the character counter or "word" to display the word count. * @default undefined */ - counter?: undefined; + counter?: "char" | "word"; /** * Set to `true` to disable the input @@ -142,6 +142,8 @@ export interface TextInputProps { export default class TextInput extends SvelteComponentTyped< TextInputProps, { + change: CustomEvent; + input: CustomEvent; click: WindowEventMap["click"]; mouseover: WindowEventMap["mouseover"]; mouseenter: WindowEventMap["mouseenter"]; @@ -151,8 +153,6 @@ export default class TextInput extends SvelteComponentTyped< focus: WindowEventMap["focus"]; blur: WindowEventMap["blur"]; paste: DocumentAndElementEventHandlersEventMap["paste"]; - input: CustomEvent; - change: CustomEvent; }, - { helperText: {}; labelText: {} } + { helperText: {}; invalidText: {}; labelText: {}; warnText: {} } > {}