Skip to content

Input 入力フィールド ​

コントロールドな単一行入力フィールド。@Binding var value で双方向バインディングし、平文 / パスワード、クリアボタン、字数上限、フォーカスリングに対応します。

契約ソース:lh-ui-core/specs/input.json · ゴールデンケース:lh-ui-core/cases/input.json(8 件、XCTest に翻訳済み、macOS ホストだけで実行可能)

基本形 ​

高さは Button に揃えます(3 段階の input.height トークン)。フォーカス時に枠線を color.focus に切り替え、フォーカスリングとして太くします。

9:41Input 基本

HTML シミュレーションプレビュー(iOS / SwiftUI の外観)であり、実機でのレンダリングではありません

swift
@State private var text = ""

LhInput(value: $text, placeholder: "内容を入力してください") { newValue in
  // onValueChange
}

サイズ ​

3 段階のサイズは input.height / paddingHorizontal / fontSize トークンに対応付けられます。

9:41Input サイズ

HTML シミュレーションプレビュー(iOS / SwiftUI の外観)であり、実機でのレンダリングではありません

パスワードとクリア ​

type: .password は SecureField として実装されます(テスト testPasswordTypeIsSecure)。 clearable は値があるときクリアボタンを表示し、タップで onValueChange("") を発火します(ゴールデンケース clearable-emits-empty-value)。

9:41Input 拡張

HTML シミュレーションプレビュー(iOS / SwiftUI の外観)であり、実機でのレンダリングではありません

swift
LhInput(value: $pwd, type: .password, clearable: true)

API ​

プロパティ ​

プロパティ説明型デフォルト値
value入力内容(コントロールドな双方向バインディング)String—
placeholderプレースホルダーテキストString""
type入力タイプ(平文 / パスワード)LhInputType.text
lhSize入力フィールドのサイズ。サイズトークンに対応付けLhInputSize.medium
disabled無効にするかどうか(コールバックを発火しない)Boolfalse
readonly読み取り専用かどうか(onValueChange を発火しない、フォーカススタイルは保持)Boolfalse
clearableクリアボタンを表示するかどうかBoolfalse
maxlength最大字数(超過すると切り詰め、ゴールデンケース maxlength-truncates-input)Int?nil
onValueChange内容変化のコールバック。payload は新しい値((String) -> Void)?nil
lhOnFocusフォーカス時のコールバック(() -> Void)?nil
lhOnBlurフォーカス外れのコールバック(() -> Void)?nil

LhInputSize ​

値heightpaddingHorizontalfontSize
.smallinput.height.small(32pt)input.paddingHorizontal.small(12pt)input.fontSize.small(13pt)
.mediuminput.height.medium(40pt)input.paddingHorizontal.medium(16pt)input.fontSize.medium(14pt)
.largeinput.height.large(48pt)input.paddingHorizontal.large(20pt)input.fontSize.large(16pt)

LhInputType ​

値実装
.textTextField
.passwordSecureField

色 ​

状態枠線文字 / プレースホルダー
デフォルトcolor.border.base(input.borderWidth)color.text.primary / color.text.placeholder
フォーカスcolor.focus(input.focusRingWidth)同上
無効color.disabled.bordercolor.disabled.text

トークン対応表 ​

トークン用途
input.height.{small,medium,large}3 段階の高さ
input.paddingHorizontal.{small,medium,large}3 段階の水平方向パディング
input.fontSize.{small,medium,large}3 段階のフォントサイズ
input.borderRadius / input.borderWidth角丸(radius.small に追従)と枠線の太さ
input.focusRingWidthフォーカスリングの幅
input.clearIconSizeクリアボタンアイコンのサイズ
color.focusフォーカス時の枠線色
color.text.{primary,placeholder,disabled}文字とプレースホルダーの色
color.border.base / color.disabled.border枠線色
color.background.default / color.disabled.bg底色

ゴールデンケース対応表 ​

case idアサーションローカルテスト
input-emits-onvaluechange入力で onValueChange("青花瓷") を発火testDefaultIsEditable
clearable-emits-empty-valueクリアで onValueChange("") を発火testClearableShowsClearButtonWhenHasValue
disabled-blocks-input無効状態は onValueChange を発火しないtestDisabledBlocksInput
readonly-blocks-input読み取り専用は onValueChange を発火しないtestReadonlyBlocksInput
placeholder-uses-placeholder-tokenプレースホルダー文字はプレースホルダー色トークンを取るtestPlaceholderUsesPlaceholderToken
focus-uses-focus-tokenフォーカスは focus トークンを消費し lhOnFocus を発火testFocusUsesFocusToken
small-size-uses-small-tokens小サイズは small サイズトークンを消費testSmallSizeUsesSmallTokens
maxlength-truncates-input字数超過で切り詰めtestMaxlengthTruncatesInput

さらに関連テスト:testPasswordTypeIsSecure / testDarkColorsComeFromDarkTokens / testDimensionsAreIdenticalInDarkMode / testInputViewInitAcceptsConstant。

bash
swift test --filter LhInputTests    # macOS ホストだけで実行可能、シミュレーター不要

lh-ui ネイティブ血脈 · iOS 端(Swift + SwiftUI)