Skip to content

Commit 99600c8

Browse files
Feat/inputfield chip v1 (#232)
* feat: add chip variant in input field * chore: add uage in the assets file * docs: add chip variant in docs * feat: add size variant large and small * feat: add truncated chip * refactor: rename classnames to kabab cases instead of camel case * chore: remove comments * chore: rename incorrect property in svg * chore: add default prop to input-field max chip support * refactor: replace elementRef with componentRef * fix: react 19
1 parent 55e5807 commit 99600c8

File tree

6 files changed

+341
-167
lines changed

6 files changed

+341
-167
lines changed

apps/www/content/primitives/components/inputField.mdx

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ The `InputField` component accepts the following props:
4242
- `prefix`: Text or symbol to show before input value (string)
4343
- `suffix`: Text or symbol to show after input value (string)
4444
- `width`: Custom width for the input field (string | number)
45+
- `chips`: Array of chip objects with label and onRemove function
4546
- `className`: Additional CSS class names
47+
- `size`: Size variant of the input field ('small' | 'large', default: 'large')
4648
- All other InputHTMLAttributes from React
4749

4850
## Variants
@@ -160,4 +162,70 @@ Input field with custom width.
160162
placeholder="Enter text"
161163
width="300px"
162164
/>`}
163-
/>
165+
/>
166+
167+
### With Chips
168+
169+
Input field that can display and manage chips/tags.
170+
171+
<Playground
172+
scope={{ InputField }}
173+
code={`
174+
<InputField
175+
label="With Chips"
176+
placeholder="Type and press Enter..."
177+
chips={[
178+
{ label: "A", onRemove: () => console.log("Remove A") },
179+
{ label: "B", onRemove: () => console.log("Remove B") }
180+
]}
181+
/>
182+
`}
183+
/>
184+
185+
### Size Variants
186+
187+
InputField comes in two sizes: small (24px) and large (32px).
188+
189+
<Playground
190+
scope={{ InputField }}
191+
code={`
192+
<div direction="column" gap="medium">
193+
<InputField
194+
label="Large Input (Default)"
195+
placeholder="32px height"
196+
/>
197+
<InputField
198+
label="Small Input"
199+
placeholder="24px height"
200+
size="small"
201+
/>
202+
</div>
203+
`}
204+
/>
205+
206+
### With Chips (Different Sizes)
207+
208+
<Playground
209+
scope={{ InputField }}
210+
code={`
211+
<div direction="column" gap="medium">
212+
<InputField
213+
label="Large Input with Chips"
214+
placeholder="Type and press Enter..."
215+
chips={[
216+
{ label: "A", onRemove: () => console.log("Remove A") },
217+
{ label: "B", onRemove: () => console.log("Remove B") }
218+
]}
219+
/>
220+
<InputField
221+
label="Small Input with Chips"
222+
placeholder="Type and press Enter..."
223+
size="small"
224+
chips={[
225+
{ label: "A", onRemove: () => console.log("Remove A") },
226+
{ label: "B", onRemove: () => console.log("Remove B") }
227+
]}
228+
/>
229+
</div>
230+
`}
231+
/>

apps/www/examples/shield-ts/assets.tsx

Lines changed: 64 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,27 @@ export const Assets = () => {
102102
to: new Date(),
103103
});
104104

105+
const [recipients, setRecipients] = useState([
106+
{ label: "A", onRemove: () => handleRemoveRecipient("A") },
107+
{ label: "B", onRemove: () => handleRemoveRecipient("B") },
108+
{ label: "C", onRemove: () => handleRemoveRecipient("C") },
109+
{ label: "D", onRemove: () => handleRemoveRecipient("D") },
110+
{ label: "E", onRemove: () => handleRemoveRecipient("E") }
111+
]);
112+
113+
const handleRemoveRecipient = (label: string) => {
114+
setRecipients(prev => prev.filter(recipient => recipient.label !== label));
115+
};
116+
117+
const handleAddRecipient = (value: string) => {
118+
if (value && !recipients.find(r => r.label === value)) {
119+
setRecipients(prev => [...prev, {
120+
label: value,
121+
onRemove: () => handleRemoveRecipient(value)
122+
}]);
123+
}
124+
};
125+
105126
const loadMoreData = useCallback(() => {
106127
if (!isLoading && hasMoreData) {
107128
setIsLoading(true);
@@ -158,28 +179,49 @@ export const Assets = () => {
158179
}, []);
159180

160181
return (
161-
<>
162-
<DataTable
163-
columns={columns}
164-
data={data}
165-
initialState={{ sorting: [{ id: "amount", desc: true }] }}
166-
isLoading={isLoading}
167-
onLoadMore={loadMoreData}
168-
>
169-
<DataTable.Toolbar>
170-
<AssetsHeader />
171-
<DataTable.FilterChips />
172-
{/* <Flex gap="small"> */}
173-
{/* <Button size="small" variant="primary" onClick={() => showToast("success")}>Show Success Toast!</Button>
174-
<Button size="small" variant="danger" onClick={() => showToast("error")}>Show Error Toast with custom icon</Button> */}
175-
{/* </Flex> */}
176-
</DataTable.Toolbar>
177-
<DataTable.Footer>
178-
<></>
179-
</DataTable.Footer>
180-
</DataTable>
181-
<ToastContainer />
182-
</>
182+
<div style={{ padding: "var(--rs-space-5)", width: "100%" }}>
183+
<Flex direction="column" gap="large" style={{ width: "100%" }}>
184+
<Flex direction="column" gap="medium" style={{ width: "100%" }}>
185+
<Flex justify="between" align="center">
186+
<Title>Assets</Title>
187+
<Button>Create Asset</Button>
188+
</Flex>
189+
190+
<InputField
191+
label="Label"
192+
placeholder="Type and press Enter..."
193+
chips={recipients}
194+
maxChipsVisible={2}
195+
size="small"
196+
onKeyDown={(e) => {
197+
if (e.key === 'Enter') {
198+
e.preventDefault();
199+
handleAddRecipient((e.target as HTMLInputElement).value);
200+
(e.target as HTMLInputElement).value = '';
201+
}
202+
}}
203+
/>
204+
205+
<div style={{ width: "100%" }}>
206+
<DataTable
207+
columns={columns}
208+
data={data}
209+
initialState={{ sorting: [{ id: "amount", desc: true }] }}
210+
isLoading={isLoading}
211+
onLoadMore={loadMoreData}
212+
>
213+
<DataTable.Toolbar>
214+
<AssetsHeader />
215+
<DataTable.FilterChips />
216+
</DataTable.Toolbar>
217+
<DataTable.Footer>
218+
<></>
219+
</DataTable.Footer>
220+
</DataTable>
221+
</div>
222+
</Flex>
223+
</Flex>
224+
</div>
183225
);
184226
};
185227

packages/raystack/v1/components/chip/chip.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ export const Chip = ({
8787
role="presentation"
8888
>
8989
<path
90-
fill-rule="evenodd"
91-
clip-rule="evenodd"
90+
fillRule="evenodd"
91+
clipRule="evenodd"
9292
d="M9.5066 3.3066C9.73115 3.08205 9.73115 2.71798 9.5066 2.49343C9.28205 2.26887 8.91798 2.26887 8.69343 2.49343L6.00001 5.18684L3.3066 2.49343C3.08205 2.26887 2.71798 2.26887 2.49343 2.49343C2.26887 2.71798 2.26887 3.08205 2.49343 3.3066L5.18684 6.00001L2.49343 8.69343C2.26887 8.91798 2.26887 9.28205 2.49343 9.5066C2.71798 9.73115 3.08205 9.73115 3.3066 9.5066L6.00001 6.81318L8.69343 9.5066C8.91798 9.73115 9.28205 9.73115 9.5066 9.5066C9.73115 9.28205 9.73115 8.91798 9.5066 8.69343L6.81318 6.00001L9.5066 3.3066Z"
9393
fill="currentColor"
9494
/>

0 commit comments

Comments
 (0)