React ટ્યુટોરિયલ

ટાઇપ કરેલા ફંક્શન ઘટકો, દરેક એક ફાઇલ, માનક પેટર્નથી નિયંત્રિત value + onChange — બધું React જેમ પહેલેથી કામ કરે છે તેમ જ કામ કરે છે.

તમે શું બનાવશો

એક નાનું સંપર્ક ફોર્મ — લેબલ સાથેનું ક્ષેત્ર, સબમિટ બટન, નિયંત્રિત સ્થિતિ, સાચું કીબોર્ડ અને સ્ક્રીન-રીડર વર્તન — પહેલાં સાદું, પછી શૈલીબદ્ધ, લગભગ 10 મિનિટમાં.

શરૂ કરતા પહેલાં

તમને git, Node 22 કે નવું, અને pnpm 10 કે નવું જોઈએ. કોઈ પણ React 18+ પ્રોજેક્ટ ચાલશે — Next.js, Vite અથવા સાદું React.

પગલું 1 — કોડ મેળવો

git clone https://github.com/LilyDesignSystem/lily-design-system
cd lily-design-system/lily-design-system-react-headless
pnpm install
pnpm test        # vitest + @testing-library/react
pnpm run storybook   # browse all 571 components

ઘટકો અહીં સપાટ ફાઇલો તરીકે છે: components/ — Button.tsx, TextInput.tsx — દરેકની બાજુમાં તેનું પરીક્ષણ, story અને દસ્તાવેજો. જે ફાઇલો જોઈએ તે તમારી એપમાં કૉપી કરો, અથવા રિપો લાવો અને તેમાંથી આયાત કરો.

પગલું 2 — તમારો પહેલો ઘટક

import Button from "lily-design-system-react-headless/components/Button";

export function SaveBar() {
  return <Button onClick={save}>Save</Button>;
}

આ દર્શાવે છે <button class="button" type="button">. Props: type, disabled, pressed (દર્શાવે છે aria-pressed), label (એક aria-label ઓવરરાઇડ કરવા), className, અને કોઈ પણ વધારાનો ગુણધર્મ મૂળ તત્ત્વ પર ફેલાય છે.

પગલું 3 — એક નાનું ફોર્મ બનાવો

import { useState } from "react";
import Form from ".../components/Form";
import Field from ".../components/Field";
import TextInput from ".../components/TextInput";
import Button from ".../components/Button";

export function ContactForm() {
  const [name, setName] = useState("");
  return (
    <Form label="Contact form" onSubmit={handleSubmit}>
      <Field label="Full name" required>
        <TextInput id="name" label="Full name" value={name} onChange={setName} required />
      </Field>
      <Button type="submit">Save</Button>
    </Form>
  );
}

Field દેખાતા label ને પોતાના prop તરીકે, અંદર મૂકેલા લેબલ ઘટક તરીકે નહીં — તેને એક વાર આપો, પર Fieldઅને TextInputનું label સુલભ નામ પૂરું પાડે છે.

2026-08-29 ના રોજ ચકાસ્યું: અગાઉના મુસદ્દાએ અલગ Label ની અંદર Fieldની અંદર મૂક્યો હતો, જેનાથી બે લેબલ (એક ખાલી) દેખાયા કારણ કે Field પહેલેથી પોતાનું label prop — ચોક્કસ ટુકડો કમ્પાઇલ કરીને ખબર પડી. રૂટ સંયુક્ત સંપર્ક-ફોર્મ રૂટ એ જ પેટર્ન છે, સાચા e2e અને axe પરીક્ષણોથી ચકાસાયેલ.

પગલું 4 — તેને શૈલી આપો

ઉપરનું બધું શુદ્ધ માળખા તરીકે રેન્ડર થાય છે, તમારી શૈલીઓ માટે તૈયાર. હૂકને શૈલી આપો — .button, .text-input, .label, .field — તમારી સ્ટાઇલશીટમાં, આના દ્વારા Tailwind યુટિલિટીનો સ્તર ચઢાવો className, અથવા તૈયાર થીમ લિંક કરો:

<link rel="stylesheet" href="/themes/united-states-web-design-system.css" />

પગલું 5 — બધું કામ કરતું જુઓ

Next.js ઉદાહરણ એપ સંપૂર્ણ કેટલોગ શૈલીબદ્ધ અને નિદર્શન સાથે છે, Playwright e2e અને axe-core આધારરેખા સાથે:

git clone https://github.com/LilyDesignSystem/lily-design-system
cd lily-design-system/lily-design-system-react-next-examples
pnpm install && pnpm run dev

આગળનાં પગલાં

રસ્તામાં પ્રશ્નો છે? મદદ પૃષ્ઠ જવાબોથી ભરેલું છે — અને જો કોઈ પગલું વધુ સ્પષ્ટ થઈ શકે, અમને કહો અને અમે ખુશીથી ટ્યુટોરિયલ સુધારીશું.