- Prop
onApply- Type
(code: string) => void | Promise<void>- Default
- —
- Requirement
- required
Docs Components Commerce
CouponInput
React example follows below.
Vue example follows below.
Angular example follows below.
Svelte example follows below.
Solid example follows below.
- parts
- —
- nodes
- —
- size
- —
- part
- —
ts
import * as React from "react";const couponInputFixture = { id: "coupon-input", placeholder: "Promo code", validCode: "GRASSROOT", appliedMessage: "10% off applied.", errorMessage: "Try GRASSROOT.",} satisfies { id: string; placeholder: string; validCode: string; appliedMessage: string; errorMessage: string;}; import { CouponInput } from "@grassroot/ui-react"; export default function CouponInputDemo() { const [status, setStatus] = React.useState<"idle" | "applied" | "error">("idle"); const [message, setMessage] = React.useState<string | undefined>(undefined); return ( <div> <CouponInput status={status} message={message} placeholder={couponInputFixture.placeholder} onApply={(code) => { const ok = code.trim().toUpperCase() === couponInputFixture.validCode; setStatus(ok ? "applied" : "error"); setMessage(ok ? couponInputFixture.appliedMessage : couponInputFixture.errorMessage); }} /> </div> );}- parts
- —
- nodes
- —
- size
- —
- part
- —
ts
<script setup lang="ts">import { ref } from "vue";const couponInputFixture = { id: "coupon-input", placeholder: "Promo code", validCode: "GRASSROOT", appliedMessage: "10% off applied.", errorMessage: "Try GRASSROOT.",} satisfies { id: string; placeholder: string; validCode: string; appliedMessage: string; errorMessage: string;}; import { CouponInput } from "@grassroot/ui-vue"; const status = ref<"idle" | "applied" | "error">("idle");const message = ref<string | undefined>(undefined);</script> <template> <div> <CouponInput :status="status" :message="message" :placeholder="couponInputFixture.placeholder" @apply=" (code) => { const ok = code.trim().toUpperCase() === couponInputFixture.validCode; status = ok ? 'applied' : 'error'; message = ok ? couponInputFixture.appliedMessage : couponInputFixture.errorMessage; } " /> </div></template>- parts
- —
- nodes
- —
- size
- —
- part
- —
ts
import { Component, signal } from "@angular/core";const couponInputFixture = { id: "coupon-input", placeholder: "Promo code", validCode: "GRASSROOT", appliedMessage: "10% off applied.", errorMessage: "Try GRASSROOT.",} satisfies { id: string; placeholder: string; validCode: string; appliedMessage: string; errorMessage: string;}; import { GrassrootCouponInput } from "@grassroot/ui-angular"; @Component({ selector: "app-coupon-input-demo", standalone: true, imports: [GrassrootCouponInput], template: ` <div> <grassroot-coupon-input [status]="status()" [message]="message()" [placeholder]="fixture.placeholder" (apply)="onApply($event)" /> </div> `,})export class CouponInputDemoComponent { protected readonly fixture = couponInputFixture; readonly status = signal<"idle" | "applied" | "error">("idle"); readonly message = signal<string | undefined>(undefined); onApply(code: string): void { const ok = code.trim().toUpperCase() === this.fixture.validCode; this.status.set(ok ? "applied" : "error"); this.message.set(ok ? this.fixture.appliedMessage : this.fixture.errorMessage); }} export default CouponInputDemoComponent;- parts
- —
- nodes
- —
- size
- —
- part
- —
ts
<script lang="ts"> import { CouponInput } from "@grassroot/ui-svelte"; const couponInputFixture = { id: "coupon-input", placeholder: "Promo code", validCode: "GRASSROOT", appliedMessage: "10% off applied.", errorMessage: "Try GRASSROOT.", } satisfies { id: string; placeholder: string; validCode: string; appliedMessage: string; errorMessage: string; }; let status = $state<"idle" | "applied" | "error">("idle"); let message = $state<string | undefined>(undefined);</script> <div> <CouponInput {status} {message} placeholder={couponInputFixture.placeholder} onApply={(code) => { const ok = code.trim().toUpperCase() === couponInputFixture.validCode; status = ok ? "applied" : "error"; message = ok ? couponInputFixture.appliedMessage : couponInputFixture.errorMessage; }} /></div>- parts
- —
- nodes
- —
- size
- —
- part
- —
ts
/** @jsxImportSource solid-js */import { createSignal } from "solid-js";const couponInputFixture = { id: "coupon-input", placeholder: "Promo code", validCode: "GRASSROOT", appliedMessage: "10% off applied.", errorMessage: "Try GRASSROOT.",} satisfies { id: string; placeholder: string; validCode: string; appliedMessage: string; errorMessage: string;}; import { CouponInput } from "@grassroot/ui-solid"; export default function CouponInputDemo() { const [status, setStatus] = createSignal<"idle" | "applied" | "error">("idle"); const [message, setMessage] = createSignal<string | undefined>(undefined); return ( <div> <CouponInput status={status()} message={message()} placeholder={couponInputFixture.placeholder} onApply={(code) => { const ok = code.trim().toUpperCase() === couponInputFixture.validCode; setStatus(ok ? "applied" : "error"); setMessage(ok ? couponInputFixture.appliedMessage : couponInputFixture.errorMessage); }} /> </div> );}Installation
API Reference
Import
import * as React from "react";
import { CouponInput } from "@grassroot/ui-react";
Props
Prop
Type
Default
Requirement
onApply(code: string) => void | Promise<void>—
required
status"error" | "idle" | "applied" | undefined—
optional
messagestring | undefined—
optional
placeholderstring | undefined—
optional
classNamestring | undefined—
optional
- Prop
status- Type
"error" | "idle" | "applied" | undefined- Default
- —
- Requirement
- optional
- Prop
message- Type
string | undefined- Default
- —
- Requirement
- optional
- Prop
placeholder- Type
string | undefined- Default
- —
- Requirement
- optional
- Prop
className- Type
string | undefined- Default
- —
- Requirement
- optional
Events
| Event | Payload |
|---|---|
onApply | (code: string) => void | Promise<void> |
Import
import { ref } from "vue";
import { CouponInput } from "@grassroot/ui-vue";
Props
Prop
Type
Default
Requirement
status"idle" | "applied" | "error" | undefined"idle"optional
messagestring | undefined—
optional
placeholderstring | undefined"Promo code"optional
pendingboolean | undefinedfalseoptional
- Prop
status- Type
"idle" | "applied" | "error" | undefined- Default
"idle"- Requirement
- optional
- Prop
message- Type
string | undefined- Default
- —
- Requirement
- optional
- Prop
placeholder- Type
string | undefined- Default
"Promo code"- Requirement
- optional
- Prop
pending- Type
boolean | undefined- Default
false- Requirement
- optional
Events
| Event | Payload |
|---|---|
apply | [code: string] |
Import
import { Component, signal } from "@angular/core";
import { GrassrootCouponInput } from "@grassroot/ui-angular";
Props
Prop
Type
Default
Requirement
status"idle" | "applied" | "error""idle"optional
messagestring—
optional
placeholderstring"Promo code"optional
pendingbooleanfalseoptional
- Prop
status- Type
"idle" | "applied" | "error"- Default
"idle"- Requirement
- optional
- Prop
message- Type
string- Default
- —
- Requirement
- optional
- Prop
placeholder- Type
string- Default
"Promo code"- Requirement
- optional
- Prop
pending- Type
boolean- Default
false- Requirement
- optional
Events
| Event | Payload |
|---|---|
apply | string |
Import
import { CouponInput } from "@grassroot/ui-svelte";
Props
Prop
Type
Default
Requirement
onApply(code: string) => void | Promise<void>—
required
status"idle" | "applied" | "error""idle"optional
messagestring—
optional
placeholderstring"Promo code"optional
pendingbooleanfalseoptional
classNamestring—
optional
- Prop
onApply- Type
(code: string) => void | Promise<void>- Default
- —
- Requirement
- required
- Prop
status- Type
"idle" | "applied" | "error"- Default
"idle"- Requirement
- optional
- Prop
message- Type
string- Default
- —
- Requirement
- optional
- Prop
placeholder- Type
string- Default
"Promo code"- Requirement
- optional
- Prop
pending- Type
boolean- Default
false- Requirement
- optional
- Prop
className- Type
string- Default
- —
- Requirement
- optional
Events
| Event | Payload |
|---|---|
onApply | (code: string) => void | Promise<void> |
Import
import { createSignal } from "solid-js";
import { CouponInput } from "@grassroot/ui-solid";
Props
Prop
Type
Default
Requirement
onApply(code: string) => void | Promise<void>—
required
status"idle" | "applied" | "error"—
optional
messagestring—
optional
placeholderstring"Promo code"optional
classNamestring—
optional
- Prop
onApply- Type
(code: string) => void | Promise<void>- Default
- —
- Requirement
- required
- Prop
status- Type
"idle" | "applied" | "error"- Default
- —
- Requirement
- optional
- Prop
message- Type
string- Default
- —
- Requirement
- optional
- Prop
placeholder- Type
string- Default
"Promo code"- Requirement
- optional
- Prop
className- Type
string- Default
- —
- Requirement
- optional
Events
| Event | Payload |
|---|---|
onApply | (code: string) => void | Promise<void> |