Forráskód Böngészése

[stdf]增强 input

dufu1991 10 hónapja
szülő
commit
90fdecb081

+ 5 - 2
docs/mds/components/input/api.md

@@ -6,9 +6,9 @@
 | titlePosition     | `'in'\|'out'\|null`                                                                                       | `'out'`   | N    | 标题位置。                      |
 | inputPosition     | `'left'\|'right'`                                                                                         | `'left'`  | N    | 输入框文字位置。                |
 | placeholder       | `string`                                                                                                  | `''`      | N    | 输入框提示文本。                |
-| radius            | `'none'\|'sm'\|'xl'\|'full'`                                                                              | `'sm'`    | N    | 圆角风格。                      |
+| radius            | `'none'\|'sm'\|'xl'\|'2xl'\|'full'`                                                                         | `'sm'`    | N    | 圆角风格。                      |
 | inputStyle        | `'block'\|'line'`                                                                                         | `'block'` | N    | 输入框风格。                    |
-| lineTransition    | `'left'\|'center'`                                                                                         | `'left'`  | N    | 线性过渡位置。                  |
+| lineTransition    | `'left'\|'center'\|null`                                                                                   | `null`    | N    | 线性过渡位置。                  |
 | duration          | `'fast'\|'base'\|'slow'\|'slower'`                                                                        | `'base'`  | N    | 过渡时间。                      |
 | autocomplete      | `boolean`                                                                                                 | `true`    | N    | 是否开启自动填充功能。          |
 | py                | `'0'\|'0.5'\|'1'\|'2'\|'3'\|'4'\|'6'`                                                                     | `'2'`     | N    | 垂直间距。                      |
@@ -16,6 +16,9 @@
 | state             | `'theme'\|'success'\|'warning'\|'error'\|'info'`                                                          | `'theme'` | N    | 状态。                          |
 | type              | `'text'\|'decimal'\|'email'\|'none'\|'numeric'\|'search'\|'tel'\|'url'\|'password'\|'number'\|'textarea'` | `'text'`  | N    | 输入框类型。                    |
 | inputmode         | `'text'\|'decimal'\|'email'\|'none'\|'numeric'\|'search'\|'tel'\|'url'\|''`                               | `''`      | N    | 指定输入的数据类型。            |
+| readonly         | `boolean`                                                                                                 | `false`   | N    | 是否只读。                      |
+| select           | `boolean`                                                                                                 | `false`   | N    | 选择模式,开启后显示下拉箭头。  |
+| required         | `boolean`                                                                                                 | `false`   | N    | 是否必填。                      |
 | maxlength         | `number`                                                                                                  | `24`      | N    | 最多可输入文本长度。            |
 | textareaMaxlength | `number`                                                                                                  | `200`     | N    | textarea 时最多可输入文本长度。 |
 | rows              | `number`                                                                                                  | `2`       | N    | textarea 时行数。               |

+ 5 - 2
docs/mds/components/input/api_en.md

@@ -6,9 +6,9 @@
 | titlePosition     | `'in'\|'out'\|null`                                                                                       | `'out'`   | N        | Title position.                   |
 | inputPosition     | `'left'\|'right'`                                                                                         | `'left'`  | N        | Input text position.              |
 | placeholder       | `string`                                                                                                  | `''`      | N        | Input placeholder text.           |
-| radius            | `'none'\|'base'\|'xl'\|'full'`                                                                            | `'base'`  | N        | Border radius style.              |
+| radius            | `'none'\|'sm'\|'xl'\|'2xl'\|'full'`                                                                         | `'sm'`    | N        | Border radius style.              |
 | inputStyle        | `'block'\|'line'`                                                                                         | `'block'` | N        | Input box style.                  |
-| lineTransition    | `'left'\|'center'`                                                                                         | `'left'`  | N        | Linear transition position.       |
+| lineTransition    | `'left'\|'center'\|null`                                                                                   | `null`    | N        | Linear transition position.       |
 | duration          | `'fast'\|'base'\|'slow'\|'slower'`                                                                        | `'base'`  | N        | Transition duration.              |
 | autocomplete      | `boolean`                                                                                                 | `true`    | N        | Whether to enable autocomplete.   |
 | py                | `'0'\|'0.5'\|'1'\|'2'\|'3'\|'4'\|'6'`                                                                     | `'2'`     | N        | Vertical padding.                 |
@@ -16,6 +16,9 @@
 | state             | `'theme'\|'success'\|'warning'\|'error'\|'info'`                                                          | `'theme'` | N        | State.                            |
 | type              | `'text'\|'decimal'\|'email'\|'none'\|'numeric'\|'search'\|'tel'\|'url'\|'password'\|'number'\|'textarea'` | `'text'`  | N        | Input type.                       |
 | inputmode         | `'text'\|'decimal'\|'email'\|'none'\|'numeric'\|'search'\|'tel'\|'url'\|''`                               | `''`      | N        | Specify input data type.          |
+| readonly         | `boolean`                                                                                                 | `false`   | N        | Whether readonly.                 |
+| select           | `boolean`                                                                                                 | `false`   | N        | Select mode, shows dropdown arrow.|
+| required         | `boolean`                                                                                                 | `false`   | N        | Whether required.                 |
 | maxlength         | `number`                                                                                                  | `24`      | N        | Maximum input text length.        |
 | textareaMaxlength | `number`                                                                                                  | `200`     | N        | Maximum text length for textarea. |
 | rows              | `number`                                                                                                  | `2`       | N        | Number of rows for textarea.      |

+ 6 - 0
docs/mds/components/input/version.md

@@ -1,3 +1,9 @@
+## 1.2.0
+
+- [!tag|A|0|]新增 `readonly` 属性,设置输入框为只读模式。
+- [!tag|A|0|]新增 `select` 属性,开启选择模式,显示下拉箭头。
+- [!tag|A|0|]新增 `required` 属性,标记输入框为必填项。
+
 ## 1.0.6
 
 - [!tag|B|3|]修复切换亮暗模式时,输入框 placeholder 字体颜色不跟随变化的问题。

+ 6 - 0
docs/mds/components/input/version_en.md

@@ -1,3 +1,9 @@
+## 1.2.0
+
+- [!tag|A|0|] Added `readonly` property to set the input box to readonly mode.
+- [!tag|A|0|] Added `select` property to enable select mode and show dropdown arrow.
+- [!tag|A|0|] Added `required` property to mark the input box as required.
+
 ## 1.0.6
 
 - [!tag|B|3|] Fix the problem that the input box placeholder font color does not follow the change when the light and dark mode is switched.

+ 40 - 7
packages/stdf/src/lib/components/input/Input.svelte

@@ -36,6 +36,9 @@
 		state: inputState = 'theme',
 		type = 'text',
 		inputmode = '',
+		readonly = false,
+		select = false,
+		required = false,
 		maxlength = 24,
 		textareaMaxlength = 200,
 		rows = 2,
@@ -150,7 +153,7 @@
 	// Vertical spacing style
 	const pyObj = { '0': 'py-0', '0.5': 'py-0.5', '1': 'py-1', '2': 'py-2', '3': 'py-3', '4': 'py-4', '6': 'py-6' };
 
-	// 获取焦点派发事件
+	// 获取焦点派发事件
 	// Get focus to dispatch events
 	const onFocus = () => {
 		focus = true;
@@ -240,7 +243,11 @@
 
 	//清除时触发
 	//Triggered when cleared
-	const clearFun = () => {
+	const clearFun = (e?: Event) => {
+		// 阻止事件冒泡,避免在 select 模式下触发焦点
+		// Prevent event bubbling to avoid triggering focus in select mode
+		e?.preventDefault();
+		e?.stopPropagation();
 		value = '';
 		onclear?.();
 		onchange?.('');
@@ -262,7 +269,12 @@
 				{#if titleChild}
 					{@render titleChild?.()}
 				{:else if title === ''}{:else}
-					<div class="mb-1 text-sm font-semibold">{title}</div>
+					<div class="relative mb-1 text-sm font-semibold">
+						{#if required}
+							<span class="text-error absolute -left-2.5 text-base">*</span>
+						{/if}
+						{title}
+					</div>
 				{/if}
 			{/if}
 			<div class="flex space-x-2 text-xs">
@@ -307,7 +319,12 @@
 			{/if}
 			<div class="flex grow flex-col">
 				{#if titlePosition === 'in'}
-					<div class="text-xs text-gray-400">{title}</div>
+					<div class="relative text-xs text-gray-400">
+						{#if required}
+							<span class="text-error absolute -left-2 text-sm">*</span>
+						{/if}
+						{title}
+					</div>
 				{/if}
 				<div class="flex space-x-1">
 					<div class="w-full">
@@ -317,7 +334,11 @@
 								use:typeAction
 								{rows}
 								inputmode={mode as 'none' | 'text' | 'decimal' | 'numeric' | 'tel' | 'email' | 'search' | 'url'}
-								placeholder={placeholder !== '' ? placeholder : title !== '' ? inputLang.pleaseInput + ' ' + title : ''}
+								placeholder={placeholder !== ''
+									? placeholder
+									: title !== ''
+										? (select ? inputLang.pleaseSelect : inputLang.pleaseInput) + ' ' + title
+										: ''}
 								class="focus:outline-hidden w-full bg-transparent font-semibold text-black dark:text-white {inputPosition === 'left'
 									? 'text-left'
 									: 'text-right'} {disabled ? 'cursor-not-allowed opacity-50' : ''}"
@@ -328,6 +349,7 @@
 								oncompositionstart={compositionstartFun}
 								autocomplete={autocomplete === true ? 'on' : 'off'}
 								{disabled}
+								readonly={readonly || select}
 								bind:this={textareaDom}
 								onkeydown={keydownFunc}
 							></textarea>
@@ -336,7 +358,11 @@
 								bind:value
 								use:typeAction
 								inputmode={mode as 'none' | 'text' | 'decimal' | 'numeric' | 'tel' | 'email' | 'search' | 'url'}
-								placeholder={placeholder !== '' ? placeholder : title !== '' ? inputLang.pleaseInput + ' ' + title : ''}
+								placeholder={placeholder !== ''
+									? placeholder
+									: title !== ''
+										? (select ? inputLang.pleaseSelect : inputLang.pleaseInput) + ' ' + title
+										: ''}
 								class="focus:outline-hidden w-full whitespace-normal bg-transparent font-semibold text-black dark:text-white {inputPosition ===
 								'left'
 									? 'text-left'
@@ -348,12 +374,13 @@
 								oncompositionstart={compositionstartFun}
 								autocomplete={autocomplete === true ? 'on' : 'off'}
 								{disabled}
+								readonly={readonly || select}
 								onkeydown={keydownFunc}
 							/>
 						{/if}
 					</div>
 					{#if clear && value !== ''}
-						<button onclick={() => clearFun()} aria-label="clear">
+						<button onclick={(e) => clearFun(e)} aria-label="clear">
 							<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" class="fill-current opacity-30">
 								<path
 									d="M12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22ZM12 10.5858L9.17157 7.75736L7.75736 9.17157L10.5858 12L7.75736 14.8284L9.17157 16.2426L12 13.4142L14.8284 16.2426L16.2426 14.8284L13.4142 12L16.2426 9.17157L14.8284 7.75736L12 10.5858Z"
@@ -378,6 +405,12 @@
 					{label5}
 				</button>
 			{/if}
+			{#if select}
+				<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" class="fill-current opacity-50">
+					<path d="M13.1717 12.0007L8.22192 7.05093L9.63614 5.63672L16.0001 12.0007L9.63614 18.3646L8.22192 16.9504L13.1717 12.0007Z">
+					</path>
+				</svg>
+			{/if}
 			{#if label6Child}
 				{@render label6Child?.()}
 			{:else if label6 === null}{:else}