Skip to content

Commit f79fa29

Browse files
committed
docs: Update README enum example to use a const object and utility methods for labels, colors, and options.
1 parent 02d8def commit f79fa29

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

README.md

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -121,24 +121,40 @@ The plugin generates:
121121

122122
```ts
123123
// resources/js/enums/order-status.ts
124-
export enum OrderStatus {
125-
Pending = "pending",
126-
Processing = "processing",
127-
Shipped = "shipped",
128-
}
129-
130-
export type OrderStatusValue = `${OrderStatus}`;
131-
132-
export const OrderStatusLabels: Record<OrderStatus, string> = {
133-
[OrderStatus.Pending]: "Pending",
134-
[OrderStatus.Processing]: "Processing",
135-
[OrderStatus.Shipped]: "Shipped",
136-
};
124+
export const OrderStatus = {
125+
PENDING: "pending",
126+
PROCESSING: "processing",
127+
SHIPPED: "shipped",
128+
} as const;
129+
130+
export type OrderStatus = (typeof OrderStatus)[keyof typeof OrderStatus];
131+
132+
export const OrderStatusUtils = {
133+
label(status: OrderStatus): string {
134+
switch (status) {
135+
case OrderStatus.PENDING:
136+
return "Pending";
137+
case OrderStatus.PROCESSING:
138+
return "Processing";
139+
case OrderStatus.SHIPPED:
140+
return "Shipped";
141+
}
142+
},
143+
144+
color(status: OrderStatus): string {
145+
switch (status) {
146+
case OrderStatus.PENDING:
147+
return "yellow";
148+
case OrderStatus.PROCESSING:
149+
return "blue";
150+
case OrderStatus.SHIPPED:
151+
return "green";
152+
}
153+
},
137154

138-
export const OrderStatusColors: Record<OrderStatus, string> = {
139-
[OrderStatus.Pending]: "yellow",
140-
[OrderStatus.Processing]: "blue",
141-
[OrderStatus.Shipped]: "green",
155+
options(): OrderStatus[] {
156+
return Object.values(OrderStatus);
157+
},
142158
};
143159
```
144160

0 commit comments

Comments
 (0)