Scoop API

scoop:scoop.ui.component:0.1.0

src/command/input.scoop

Selected production source · src/command/input.scoop

1package scoop.ui.component
3import scoop.graphics.*
4import scoop.icons.lucide.search as searchIcon
5import scoop.ui.*
6import scoop.ui.style.*
7import scoop.ui.style.Theme
8import scoop.window.accessibility.*
10internal fun commandInput(
11 input: CommandProps,
12 focus: FocusHandle,
13 theme: Theme,
14 collection: SemanticNodeId?,
15 active: ViewKey?
16): View {
17 val field = input.input
18 val density = theme.tokens.typography.body.fontSize / 14.0
19 val editor =
20 InputProps(
21 field.state,
22 field.placeholder,
23 field.enabled,
24 field.readOnly,
25 field.invalid,
26 field.description,
27 field.fonts,
28 field.style,
29 field.theme,
30 field.focus.copy { handle = Some(focus) },
31 field.direction,
32 field.alignment,
33 field.paintCache,
34 field.caretBlink,
35 field.onEdited,
36 field.onSubmit,
37 field.policy,
38 field.projection,
39 field.copy,
40 field.labelTarget,
41 field.group,
42 field.chrome,
43 field.contextMenu,
44 field.protectedText,
45 candidateInputSemantics(field.semantics, collection, active),
46 field.acceptDrops,
47 field.drag,
48 field.touch,
49 field.touchScroll,
50 field.scrollPhysics,
51 inputPurpose = field.inputPurpose,
52 softwareKeyboard = field.softwareKeyboard,
53 primarySelection = field.primarySelection,
54 automaticTextReplacement = field.automaticTextReplacement
55 )
56 val addons = ArrayList<InputGroupAddon>()
57 if (input.showSearchIcon)
58 addons.add(
59 InputGroupAddon(
60 input.searchIcon ?:
61 makeIcon(searchIcon) {
62 size = 16.0 * density
63 color =
64 Some(
65 componentForeground(
66 theme,
67 theme.tokens.palette.muted.foreground,
68 theme.tokens.palette.background.background,
69 3.0
70 )
71 )
72 },
73 key = ViewKey.Text("search")
74 )
75 )
76 val group =
77 component(
78 InputGroupProps(
79 InputGroupControl.Input(editor),
80 addons.toArray(),
81 enabled = field.enabled,
82 invalid = field.invalid,
83 fonts = field.fonts,
84 theme = field.theme,
85 surface =
86 field.style.surface.copy {
87 style = commandInputDecoration(theme).then(field.style.surface.style)
88 }
89 ),
90 { current, mount -> InputGroup(current, scope = mount) }
91 )
92 return panelFrame(group, Insets(16.0 * density, 16.0 * density, 16.0 * density, 4.0 * density))
95internal fun commandInputDecoration(theme: Theme): StyleOverride {
96 val colors = theme.tokens.palette
97 val ink = colors.input.withAlpha(colors.input.alpha * 0.3)
98 return styleOverride {
99 background(
100 Some(
101 Paint(
102 if (theme.preferences.highContrast)
103 colors.background.background
104 else
105 componentBackground(theme, ink)
106 )
107 )
108 )
109 border(
110 Some(
111 Border.all(1.0, componentForeground(theme, ink, colors.background.background, 3.0))
112 )
113 )
114 corners(Corners.all(8.0 * theme.tokens.typography.body.fontSize / 14.0))
115 boxShadows([])
116 }