Skip to content

Commit fae93f7

Browse files
authored
Merge pull request #382 from code0-tech/feat/#215
Suggestions
2 parents 5c0ab96 + 66b3177 commit fae93f7

File tree

4 files changed

+46
-16
lines changed

4 files changed

+46
-16
lines changed

.storybook/global.scss

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ html {
44
}
55

66
.sb-show-main {
7-
background: url(https://applescoop.org/image/wallpapers/mac/windows-10-stock-hd-cells-glowing-dark-22-09-2024-1727068449-hd-wallpaper.jpeg);
8-
transition: background-color 0.3s;
9-
background-position: center;
10-
background-size: cover;
7+
background: #030014 !important;
118
}
129

1310
.sb-main-fullscreen {

src/components/d-flow/suggestions/DFlowSuggestionMenu.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const SuggestionMenu = () => {
4444
return <div>
4545
<TextInput title={"Text"}
4646
clearable
47+
transformValue={(value) => <span style={{color: "red"}}>{value}</span>}
4748
suggestionsFooter={<DFlowSuggestionMenuFooter/>}
4849
suggestions={toInputSuggestions(result)}
4950
description={"Type what ever text you like"}

src/components/form/Input.style.scss

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@
2323
@include box.boxActiveStyle(variables.$primary, variables.$white, variables.$white);
2424
}
2525

26+
&__syntax {
27+
position: absolute;
28+
z-index: -1;
29+
overflow: hidden;
30+
font-size: variables.$sm;
31+
color: rgba(variables.$white, .5);
32+
white-space: nowrap;
33+
padding: $padding $padding;
34+
box-sizing: border-box;
35+
36+
}
37+
2638
&__left, &__right {
2739
display: flex;
2840
align-items: stretch;
@@ -73,11 +85,16 @@
7385
width: 100%;
7486
box-shadow: none;
7587
font-size: variables.$sm;
88+
box-sizing: border-box;
7689
color: rgba(variables.$white, .5);
7790

7891
& {
7992
@include helpers.fontStyle();
8093
}
94+
95+
&--syntax {
96+
color: transparent;
97+
}
8198
}
8299

83100

src/components/form/Input.tsx

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,20 @@ export type Code0Input = Omit<
5555

5656
// Input component props definition
5757
export interface InputProps<T> extends Code0Input, ValidationProps<T> {
58-
suggestions?: InputSuggestion[]; // Optional suggestions shown in dropdown
59-
suggestionsHeader?: React.ReactNode; // Custom header above suggestions
60-
suggestionsFooter?: React.ReactNode; // Custom footer below suggestions
61-
wrapperComponent?: Code0Component<HTMLDivElement>; // Props for the wrapping div
62-
right?: React.ReactNode; // Right-side icon or element
63-
left?: React.ReactNode; // Left-side icon or element
64-
leftType?: "action" | "placeholder" | "icon"; // Visual type for left slot
65-
rightType?: "action" | "placeholder" | "icon"; // Visual type for right slot
66-
title?: React.ReactNode; // Input label
67-
description?: React.ReactNode; // Label description below title
58+
59+
suggestions?: InputSuggestion[] // Optional suggestions shown in dropdown
60+
suggestionsHeader?: React.ReactNode // Custom header above suggestions
61+
suggestionsFooter?: React.ReactNode // Custom footer below suggestions
62+
transformValue?: (value: T) => React.ReactNode | T // Optional value transformation function
63+
64+
wrapperComponent?: Code0Component<HTMLDivElement> // Props for the wrapping div
65+
right?: React.ReactNode // Right-side icon or element
66+
left?: React.ReactNode // Left-side icon or element
67+
leftType?: "action" | "placeholder" | "icon" // Visual type for left slot
68+
rightType?: "action" | "placeholder" | "icon" // Visual type for right slot
69+
title?: React.ReactNode // Input label
70+
description?: React.ReactNode // Label description below title
71+
6872
}
6973

7074
const Input: ForwardRefExoticComponent<InputProps<any>> = React.forwardRef(
@@ -137,7 +141,7 @@ const Input: ForwardRefExoticComponent<InputProps<any>> = React.forwardRef(
137141
<MenuTrigger asChild>
138142
<input
139143
ref={inputRef as LegacyRef<HTMLInputElement>} // Cast for TS compatibility
140-
{...mergeCode0Props("input__control", rest)} // Merge styling and native props
144+
{...mergeCode0Props(`input__control ${props.transformValue ? "input__control--syntax" : ""}`, rest)}
141145
onFocus={() => !open && setOpen(true)} // Open on focus
142146
onKeyDown={(e) => {
143147
if (e.key === "ArrowDown") {
@@ -188,10 +192,21 @@ const Input: ForwardRefExoticComponent<InputProps<any>> = React.forwardRef(
188192
<input
189193
tabIndex={2} // Ensure keyboard tab order
190194
ref={inputRef as LegacyRef<HTMLInputElement>}
191-
{...mergeCode0Props("input__control", rest)} // Basic input styling and props
195+
{...mergeCode0Props(`input__control ${props.transformValue ? "input__control--syntax" : ""}`, rest)} // Basic input styling and props
192196
/>
193197
)}
194198

199+
{props.transformValue ? (
200+
<div className={"input__syntax"} style={{
201+
width: inputRef?.current?.clientWidth ?? 0,
202+
height: inputRef?.current?.clientHeight ?? 0,
203+
top: inputRef?.current?.offsetTop ?? 0,
204+
left: inputRef?.current?.offsetLeft ?? 0,
205+
}}>
206+
{props.transformValue(inputRef?.current?.value ?? inputRef?.current?.placeholder ?? "sd" )} {/* Render transformed value */}
207+
</div>
208+
) : null}
209+
195210
{right &&
196211
<div className={`input__right input__right--${rightType}`}>{right}</div>} {/* Right element */}
197212
</div>

0 commit comments

Comments
 (0)