create-guren-app 1.19.0 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/package.json +1 -1
  2. package/templates/api-only/.oxlintrc.json +7 -0
  3. package/templates/api-only/package.json +1 -1
  4. package/templates/blog/.guren/api-client.gen.ts +3 -0
  5. package/templates/blog/.guren/forms.gen.ts +60 -0
  6. package/templates/blog/.guren/routes.gen.ts +3 -0
  7. package/templates/blog/app/Http/Controllers/Auth/LoginController.ts +1 -2
  8. package/templates/blog/app/Http/Controllers/Auth/RegisterController.ts +1 -2
  9. package/templates/blog/app/Http/Controllers/ProfileController.ts +1 -2
  10. package/templates/blog/app/Http/Middleware/AuthThrottle.ts +42 -11
  11. package/templates/blog/app/Http/Validators/LoginValidator.ts +4 -3
  12. package/templates/blog/app/Http/Validators/ProfileValidator.ts +2 -2
  13. package/templates/blog/resources/js/pages/auth/Login.tsx +16 -75
  14. package/templates/blog/resources/js/pages/auth/Register.tsx +15 -99
  15. package/templates/blog/resources/js/pages/dashboard/Index.tsx +2 -4
  16. package/templates/blog/resources/js/pages/profile/Edit.tsx +14 -75
  17. package/templates/blog/routes/auth.ts +6 -3
  18. package/templates/default/.oxlintrc.json +7 -0
  19. package/templates/default/package.json +2 -2
  20. package/templates/default/resources/css/guren.css +2 -0
  21. package/templates/default/resources/js/components/ui/Alert.tsx +29 -0
  22. package/templates/default/resources/js/components/ui/Button.tsx +46 -0
  23. package/templates/default/resources/js/components/ui/Card.tsx +17 -0
  24. package/templates/default/resources/js/components/ui/Checkbox.tsx +17 -0
  25. package/templates/default/resources/js/components/ui/Field.tsx +68 -0
  26. package/templates/default/resources/js/components/ui/Input.tsx +10 -0
  27. package/templates/default/resources/js/components/ui/Label.tsx +6 -0
  28. package/templates/default/resources/js/components/ui/Select.tsx +29 -0
  29. package/templates/default/resources/js/components/ui/Textarea.tsx +10 -0
  30. package/templates/default/resources/js/pages/Home.tsx +4 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-guren-app",
3
- "version": "1.19.0",
3
+ "version": "1.20.0",
4
4
  "description": "Scaffold a Guren app: a Bun-first fullstack TypeScript framework with Laravel-style conventions, Inertia.js + React, Drizzle ORM, and an agent harness for Claude Code and other coding agents.",
5
5
  "keywords": [
6
6
  "guren",
@@ -24,6 +24,13 @@
24
24
  // `env` a config definition receives. bin/ and drizzle.config.ts run outside the app.
25
25
  "files": ["app/**", "config/**", "routes/**", "src/**", "modules/*/**"],
26
26
  "rules": { "guren/no-unvalidated-env-read": "error" }
27
+ },
28
+ {
29
+ // Pages and components style with the Guren UI tokens in resources/css/guren.css
30
+ // (bg-g-panel, text-g-text, var(--g-accent)), which carry the dark theme; a
31
+ // palette class or a hex literal does not.
32
+ "files": ["resources/js/**"],
33
+ "rules": { "guren/no-raw-color": "error" }
27
34
  }
28
35
  ]
29
36
  // Type-aware rules (typescript/no-floating-promises and friends) need
@@ -21,7 +21,7 @@
21
21
  "test": "bun test"
22
22
  },
23
23
  "dependencies": {
24
- "@guren/cli": "^2.32.0",
24
+ "@guren/cli": "^2.33.0",
25
25
  "@guren/core": "^1.25.0",
26
26
  "@guren/orm": "^2.15.0",
27
27
  "drizzle-orm": "1.0.0-rc.4"
@@ -29,6 +29,7 @@ export interface ApiRoutes {
29
29
  'login.store': {
30
30
  method: 'POST'
31
31
  path: '/login'
32
+ body: { email: string; password: string; remember?: boolean | string }
32
33
  }
33
34
  'logout': {
34
35
  method: 'POST'
@@ -77,6 +78,7 @@ export interface ApiRoutes {
77
78
  'profile.update': {
78
79
  method: 'PUT'
79
80
  path: '/profile'
81
+ body: { name: string; email: string; password?: string }
80
82
  }
81
83
  'register': {
82
84
  method: 'GET'
@@ -85,6 +87,7 @@ export interface ApiRoutes {
85
87
  'register.store': {
86
88
  method: 'POST'
87
89
  path: '/register'
90
+ body: { name: string; email: string; password: string; passwordConfirmation: string }
88
91
  }
89
92
  }
90
93
 
@@ -0,0 +1,60 @@
1
+ // Generated — DO NOT EDIT
2
+ // Run `guren codegen` to regenerate.
3
+ import type { RouteFormContract } from '@guren/inertia-client/forms'
4
+ import type { ApiRoutes } from './api-client.gen'
5
+
6
+ export const loginStoreForm: RouteFormContract<'login.store', 'POST', '/login', ApiRoutes['login.store']['body']> = {
7
+ route: 'login.store',
8
+ method: 'POST',
9
+ path: '/login',
10
+ fields: {
11
+ email: { type: 'string', required: true, format: 'email', minLength: 1 },
12
+ password: { type: 'string', required: true, minLength: 1 },
13
+ remember: { type: 'boolean', required: false },
14
+ },
15
+ }
16
+
17
+ export const postsStoreForm: RouteFormContract<'posts.store', 'POST', '/posts', ApiRoutes['posts.store']['body']> = {
18
+ route: 'posts.store',
19
+ method: 'POST',
20
+ path: '/posts',
21
+ fields: {
22
+ title: { type: 'string', required: true, minLength: 1, maxLength: 255 },
23
+ excerpt: { type: 'string', required: true, minLength: 1, maxLength: 500 },
24
+ body: { type: 'string', required: true, minLength: 1 },
25
+ },
26
+ }
27
+
28
+ export const postsUpdateForm: RouteFormContract<'posts.update', 'PUT', '/posts/:id', ApiRoutes['posts.update']['body']> = {
29
+ route: 'posts.update',
30
+ method: 'PUT',
31
+ path: '/posts/:id',
32
+ fields: {
33
+ title: { type: 'string', required: true, minLength: 1, maxLength: 255 },
34
+ excerpt: { type: 'string', required: true, minLength: 1, maxLength: 500 },
35
+ body: { type: 'string', required: true, minLength: 1 },
36
+ },
37
+ }
38
+
39
+ export const profileUpdateForm: RouteFormContract<'profile.update', 'PUT', '/profile', ApiRoutes['profile.update']['body']> = {
40
+ route: 'profile.update',
41
+ method: 'PUT',
42
+ path: '/profile',
43
+ fields: {
44
+ name: { type: 'string', required: true, minLength: 1, maxLength: 120 },
45
+ email: { type: 'string', required: true, format: 'email', minLength: 1 },
46
+ password: { type: 'string', required: false },
47
+ },
48
+ }
49
+
50
+ export const registerStoreForm: RouteFormContract<'register.store', 'POST', '/register', ApiRoutes['register.store']['body']> = {
51
+ route: 'register.store',
52
+ method: 'POST',
53
+ path: '/register',
54
+ fields: {
55
+ name: { type: 'string', required: true, minLength: 1, maxLength: 120 },
56
+ email: { type: 'string', required: true, format: 'email', minLength: 1 },
57
+ password: { type: 'string', required: true, minLength: 8 },
58
+ passwordConfirmation: { type: 'string', required: true, minLength: 1 },
59
+ },
60
+ }
@@ -147,9 +147,12 @@ function appendQueryString(path: string, query?: RouteQuery): string {
147
147
  declare module '@guren/core' {
148
148
  interface GurenRouteContracts {
149
149
  routes: {
150
+ 'login.store': { body: { email: string; password: string; remember: boolean } }
150
151
  'posts.search': { body: { keywords: string[]; limit: number } }
151
152
  'posts.store': { body: { title: string; excerpt: string; body: string } }
152
153
  'posts.update': { body: { title: string; excerpt: string; body: string } }
154
+ 'profile.update': { body: { name: string; email: string; password: string } }
155
+ 'register.store': { body: { name: string; email: string; password: string; passwordConfirmation: string } }
153
156
  }
154
157
  }
155
158
  }
@@ -1,5 +1,4 @@
1
1
  import { Controller, ValidationException } from '@guren/core'
2
- import { LoginSchema } from '../../Validators/LoginValidator.js'
3
2
  import { pages } from '@/.guren/pages.gen'
4
3
 
5
4
  export default class LoginController extends Controller {
@@ -9,7 +8,7 @@ export default class LoginController extends Controller {
9
8
  }
10
9
 
11
10
  async store(): Promise<Response> {
12
- const { email, password, remember } = await this.validateBody(LoginSchema)
11
+ const { email, password, remember } = this.validated('login.store').body
13
12
 
14
13
  this.auth.session()?.regenerate()
15
14
 
@@ -1,5 +1,4 @@
1
1
  import { Controller, ValidationException } from '@guren/core'
2
- import { RegisterSchema } from '../../Validators/RegisterValidator.js'
3
2
  import { User } from '../../../Models/User.js'
4
3
  import { pages } from '@/.guren/pages.gen'
5
4
 
@@ -9,7 +8,7 @@ export default class RegisterController extends Controller {
9
8
  }
10
9
 
11
10
  async store(): Promise<Response> {
12
- const { name, email, password } = await this.validateBody(RegisterSchema)
11
+ const { name, email, password } = this.validated('register.store').body
13
12
 
14
13
  const existing = await User.where({ email })
15
14
  if (existing.length > 0) {
@@ -1,6 +1,5 @@
1
1
  import { Controller, ValidationException } from '@guren/core'
2
2
  import { User, type UserRecord } from '../../Models/User.js'
3
- import { ProfileUpdateSchema } from '../Validators/ProfileValidator.js'
4
3
  import { pages } from '@/.guren/pages.gen'
5
4
 
6
5
  export default class ProfileController extends Controller {
@@ -24,7 +23,7 @@ export default class ProfileController extends Controller {
24
23
  return this.redirect('/login')
25
24
  }
26
25
 
27
- const { name, email, password } = await this.validateBody(ProfileUpdateSchema)
26
+ const { name, email, password } = this.validated('profile.update').body
28
27
  const emailChanged = email !== user.email
29
28
 
30
29
  if (emailChanged) {
@@ -1,13 +1,19 @@
1
- import { createRateLimitMiddleware, getRequestTranslator, ValidationException } from '@guren/core'
2
- import type { Context, Middleware } from '@guren/core'
1
+ import { AUTH_CONTEXT_KEY, createRateLimitMiddleware, getRequestTranslator, ValidationException } from '@guren/core'
2
+ import type { AuthContext, Context, Middleware } from '@guren/core'
3
3
 
4
4
  interface ThrottleOptions {
5
- /** Requests allowed per client and email address within the window. */
5
+ /** Requests allowed per key within the window. */
6
6
  limit: number
7
7
  windowMs: number
8
8
  /** Translation key; `:seconds` is replaced with the wait. */
9
9
  messageKey: string
10
10
  fallbackMessage: string
11
+ /** Defaults to the client IP and the submitted email. */
12
+ key?: (ctx: Context) => Promise<string>
13
+ /** A request this returns true for is not counted. */
14
+ skip?: (ctx: Context) => Promise<boolean>
15
+ /** The form field an Inertia request shows the message under. */
16
+ errorField?: string
11
17
  }
12
18
 
13
19
  interface BunServerEnv {
@@ -21,18 +27,23 @@ function clientIp(ctx: Context): string | undefined {
21
27
  }
22
28
 
23
29
  // Hono caches the parsed body, so the controller still reads it after this.
24
- async function submittedEmail(ctx: Context): Promise<string | undefined> {
30
+ // `undefined` when the body cannot be read as an object.
31
+ async function submittedBody(ctx: Context): Promise<Record<string, unknown> | undefined> {
25
32
  try {
26
33
  const body: unknown = (ctx.req.header('content-type') ?? '').includes('application/json')
27
34
  ? await ctx.req.json()
28
35
  : await ctx.req.parseBody()
29
- const email = (body as Record<string, unknown> | null)?.email
30
- return typeof email === 'string' ? email.trim().toLowerCase() : undefined
36
+ return typeof body === 'object' && body !== null ? (body as Record<string, unknown>) : undefined
31
37
  } catch {
32
38
  return undefined
33
39
  }
34
40
  }
35
41
 
42
+ async function submittedEmail(ctx: Context): Promise<string | undefined> {
43
+ const email = (await submittedBody(ctx))?.email
44
+ return typeof email === 'string' ? email.trim().toLowerCase() : undefined
45
+ }
46
+
36
47
  function throttleMessage(ctx: Context, options: ThrottleOptions, seconds: number): string {
37
48
  const translated = getRequestTranslator(ctx)?.t(options.messageKey, { seconds })
38
49
  return translated && translated !== options.messageKey
@@ -41,9 +52,9 @@ function throttleMessage(ctx: Context, options: ThrottleOptions, seconds: number
41
52
  }
42
53
 
43
54
  /**
44
- * Counts every request, keyed per client IP and submitted email. The default
45
- * store lives in process memory: pass `store: new RedisRateLimitStore(redis)`
46
- * (from `@guren/core/redis`) to share counts across instances.
55
+ * Counts every request `skip` lets through, per `key`. The default store lives
56
+ * in process memory: pass `store: new RedisRateLimitStore(redis)` (from
57
+ * `@guren/core/redis`) to share counts across instances.
47
58
  */
48
59
  function authThrottle(name: string, options: ThrottleOptions): Middleware {
49
60
  // Built on the first request: the default store starts a sweep timer, which
@@ -54,12 +65,13 @@ function authThrottle(name: string, options: ThrottleOptions): Middleware {
54
65
  limit: options.limit,
55
66
  windowMs: options.windowMs,
56
67
  keyPrefix: `auth:${name}:`,
57
- keyGenerator: async (ctx) => `${clientIp(ctx) ?? 'unknown'}|${(await submittedEmail(ctx)) ?? ''}`,
68
+ keyGenerator: options.key ?? (async (ctx) => `${clientIp(ctx) ?? 'unknown'}|${(await submittedEmail(ctx)) ?? ''}`),
69
+ skip: options.skip,
58
70
  onRateLimited: (ctx, retryAfter) => {
59
71
  const message = throttleMessage(ctx, options, retryAfter)
60
72
  // An Inertia form shows a flashed error; a bare 429 would open its error modal.
61
73
  if (ctx.req.header('x-inertia') === 'true') {
62
- throw ValidationException.withMessages({ message })
74
+ throw ValidationException.withMessages({ [options.errorField ?? 'message']: message })
63
75
  }
64
76
  return ctx.json({ message, retryAfter }, 429)
65
77
  },
@@ -88,3 +100,22 @@ export const throttlePasswordResetRequest = authThrottle('forgot-password', {
88
100
  messageKey: 'auth.too_many_requests',
89
101
  fallbackMessage: 'Too many requests. Please try again in :seconds seconds.',
90
102
  })
103
+
104
+ // Per signed-in user, so a stolen session cannot guess the current password the
105
+ // profile form asks for. Only a request carrying one reaches that check.
106
+ export const throttleProfileUpdate = authThrottle('profile', {
107
+ limit: 5,
108
+ windowMs: 60_000,
109
+ messageKey: 'auth.too_many_requests',
110
+ fallbackMessage: 'Too many requests. Please try again in :seconds seconds.',
111
+ key: async (ctx) => {
112
+ const id = await (ctx.get(AUTH_CONTEXT_KEY) as AuthContext | undefined)?.id()
113
+ return id === undefined || id === null ? `ip:${clientIp(ctx) ?? 'unknown'}` : `user:${String(id)}`
114
+ },
115
+ // Mirrors the controller's `currentPassword === ''`; an unreadable body is counted.
116
+ skip: async (ctx) => {
117
+ const body = await submittedBody(ctx)
118
+ return body !== undefined && (body.currentPassword === undefined || body.currentPassword === '')
119
+ },
120
+ errorField: 'currentPassword',
121
+ })
@@ -12,15 +12,16 @@ export const LoginSchema = z.object({
12
12
  password: z
13
13
  .string()
14
14
  .min(1, 'Password is required.'),
15
+ // Each branch ends in a boolean schema, so codegen types the parsed value as
16
+ // a boolean (it cannot see what a trailing transform returns).
15
17
  remember: z
16
18
  .union([
17
19
  z.boolean(),
18
20
  z
19
21
  .string()
20
- .transform((value) => ['true', 'on', '1'].includes(value.toLowerCase())),
22
+ .transform((value) => ['true', 'on', '1'].includes(value.toLowerCase()))
23
+ .pipe(z.boolean()),
21
24
  ])
22
- .optional()
23
- .transform((value) => Boolean(value))
24
25
  .default(false),
25
26
  })
26
27
 
@@ -12,11 +12,11 @@ export const ProfileUpdateSchema = z.object({
12
12
  .min(1, 'Email is required.')
13
13
  .toLowerCase()
14
14
  .pipe(z.email('Enter a valid email address.')),
15
+ // A default rather than a transform, so codegen types the parsed value as a string.
15
16
  password: z
16
17
  .string()
17
18
  .trim()
18
- .optional()
19
- .transform((value) => value ?? '')
19
+ .default('')
20
20
  .refine((value) => value === '' || value.length >= 8, 'Password must be at least 8 characters.'),
21
21
  })
22
22
 
@@ -1,6 +1,10 @@
1
- import { Head, Link, useForm } from '@inertiajs/react'
2
- import { useId } from 'react'
1
+ import { Head, Link } from '@inertiajs/react'
2
+ import { useRouteForm } from '@guren/inertia-client/forms'
3
3
  import Layout from '../../components/Layout.js'
4
+ import { loginStoreForm } from '@/.guren/forms.gen'
5
+ import { Alert } from '@/resources/js/components/ui/Alert'
6
+ import { Button } from '@/resources/js/components/ui/Button'
7
+ import { Field } from '@/resources/js/components/ui/Field'
4
8
  import type { ValidationErrors } from '@guren/core'
5
9
 
6
10
  interface Props {
@@ -8,21 +12,9 @@ interface Props {
8
12
  errors?: ValidationErrors<'email' | 'password'>
9
13
  }
10
14
 
11
- type LoginFormData = {
12
- email: string
13
- password: string
14
- remember: boolean
15
- }
16
-
17
15
  export default function Login({ email = '', errors = {} }: Props) {
18
- const form = useForm<LoginFormData>({
19
- email,
20
- password: '',
21
- remember: false,
22
- })
23
-
24
- const emailId = useId()
25
- const passwordId = useId()
16
+ // Shows a redirect-back's field errors even when this form did not make the visit.
17
+ const form = useRouteForm(loginStoreForm, { email, password: '', remember: false }, { adoptPageErrors: true })
26
18
 
27
19
  return (
28
20
  <Layout>
@@ -37,69 +29,18 @@ export default function Login({ email = '', errors = {} }: Props) {
37
29
  </p>
38
30
 
39
31
  {errors.message && (
40
- <p className="mt-4 flex gap-3 border-y border-g-line py-2.5 text-sm">
41
- <span className="w-10 shrink-0 text-right font-mono text-xs font-bold leading-5 text-g-danger">error</span>
42
- <span className="text-g-text">{errors.message}</span>
43
- </p>
32
+ <Alert tone="danger" className="mt-4">{errors.message}</Alert>
44
33
  )}
45
34
 
46
- <form
47
- className="mt-6 space-y-4"
48
- onSubmit={(event) => {
49
- event.preventDefault()
50
- form.post('/login')
51
- }}
52
- >
53
- <div>
54
- <label htmlFor={emailId} className="block text-sm font-bold text-g-heading">
55
- Email
56
- </label>
57
- <input
58
- id={emailId}
59
- type="email"
60
- value={form.data.email}
61
- onChange={(event) => form.setData('email', event.target.value)}
62
- required
63
- className="mt-1 w-full rounded-g-ctl border border-g-line-strong bg-g-panel px-3 py-2 text-g-text transition outline-none placeholder:text-g-muted focus:border-transparent focus:outline-2 focus:-outline-offset-1 focus:outline-g-accent"
64
- />
65
- {errors.email && <p className="mt-1 text-sm text-g-danger">{errors.email}</p>}
66
- </div>
67
-
68
- <div>
69
- <label htmlFor={passwordId} className="block text-sm font-bold text-g-heading">
70
- Password
71
- </label>
72
- <input
73
- id={passwordId}
74
- type="password"
75
- value={form.data.password}
76
- onChange={(event) => form.setData('password', event.target.value)}
77
- required
78
- className="mt-1 w-full rounded-g-ctl border border-g-line-strong bg-g-panel px-3 py-2 text-g-text transition outline-none placeholder:text-g-muted focus:border-transparent focus:outline-2 focus:-outline-offset-1 focus:outline-g-accent"
79
- />
80
- {errors.password && <p className="mt-1 text-sm text-g-danger">{errors.password}</p>}
81
- </div>
82
-
83
- <label className="flex items-center gap-2 text-sm text-g-text">
84
- <input
85
- type="checkbox"
86
- checked={form.data.remember}
87
- onChange={(event) => form.setData('remember', event.target.checked)}
88
- className="h-4 w-4 rounded accent-g-accent"
89
- />
90
- Remember me
91
- </label>
92
-
93
- <button
94
- type="submit"
95
- disabled={form.processing}
96
- className="w-full rounded-g-ctl bg-g-accent px-4 py-2 text-sm font-bold text-g-on-accent transition hover:bg-g-accent-down disabled:cursor-not-allowed disabled:opacity-45"
97
- >
98
- Sign in
99
- </button>
35
+ <form className="mt-6 space-y-4" onSubmit={form.handleSubmit}>
36
+ <Field form={form} name="email" />
37
+ <Field form={form} name="password" as="password" />
38
+ <Field form={form} name="remember" label="Remember me" />
39
+ <Button type="submit" disabled={form.processing} block>
40
+ Sign in
41
+ </Button>
100
42
  </form>
101
43
 
102
-
103
44
  <p className="mt-6 text-center text-sm text-g-text-2">
104
45
  Don&apos;t have an account?{' '}
105
46
  <Link href="/register" className="text-g-accent-text transition hover:underline">
@@ -1,31 +1,18 @@
1
- import { Head, Link, useForm } from '@inertiajs/react'
2
- import { useId } from 'react'
1
+ import { Head, Link } from '@inertiajs/react'
2
+ import { useRouteForm } from '@guren/inertia-client/forms'
3
3
  import Layout from '../../components/Layout.js'
4
+ import { registerStoreForm } from '@/.guren/forms.gen'
5
+ import { Alert } from '@/resources/js/components/ui/Alert'
6
+ import { Button } from '@/resources/js/components/ui/Button'
7
+ import { Field } from '@/resources/js/components/ui/Field'
4
8
  import type { ValidationErrors } from '@guren/core'
5
9
 
6
10
  interface Props {
7
11
  errors?: ValidationErrors<'name' | 'email' | 'password' | 'passwordConfirmation'>
8
12
  }
9
13
 
10
- type RegisterFormData = {
11
- name: string
12
- email: string
13
- password: string
14
- passwordConfirmation: string
15
- }
16
-
17
14
  export default function Register({ errors = {} }: Props) {
18
- const form = useForm<RegisterFormData>({
19
- name: '',
20
- email: '',
21
- password: '',
22
- passwordConfirmation: '',
23
- })
24
-
25
- const nameId = useId()
26
- const emailId = useId()
27
- const passwordId = useId()
28
- const passwordConfirmationId = useId()
15
+ const form = useRouteForm(registerStoreForm, { name: '', email: '', password: '', passwordConfirmation: '' })
29
16
 
30
17
  return (
31
18
  <Layout>
@@ -40,88 +27,17 @@ export default function Register({ errors = {} }: Props) {
40
27
  </p>
41
28
 
42
29
  {errors.message && (
43
- <p className="mt-4 flex gap-3 border-y border-g-line py-2.5 text-sm">
44
- <span className="w-10 shrink-0 text-right font-mono text-xs font-bold leading-5 text-g-danger">error</span>
45
- <span className="text-g-text">{errors.message}</span>
46
- </p>
30
+ <Alert tone="danger" className="mt-4">{errors.message}</Alert>
47
31
  )}
48
32
 
49
- <form
50
- className="mt-6 space-y-4"
51
- onSubmit={(event) => {
52
- event.preventDefault()
53
- form.post('/register')
54
- }}
55
- >
56
- <div>
57
- <label htmlFor={nameId} className="block text-sm font-bold text-g-heading">
58
- Name
59
- </label>
60
- <input
61
- id={nameId}
62
- type="text"
63
- value={form.data.name}
64
- onChange={(event) => form.setData('name', event.target.value)}
65
- required
66
- className="mt-1 w-full rounded-g-ctl border border-g-line-strong bg-g-panel px-3 py-2 text-g-text transition outline-none placeholder:text-g-muted focus:border-transparent focus:outline-2 focus:-outline-offset-1 focus:outline-g-accent"
67
- />
68
- {errors.name && <p className="mt-1 text-sm text-g-danger">{errors.name}</p>}
69
- </div>
70
-
71
- <div>
72
- <label htmlFor={emailId} className="block text-sm font-bold text-g-heading">
73
- Email
74
- </label>
75
- <input
76
- id={emailId}
77
- type="email"
78
- value={form.data.email}
79
- onChange={(event) => form.setData('email', event.target.value)}
80
- required
81
- className="mt-1 w-full rounded-g-ctl border border-g-line-strong bg-g-panel px-3 py-2 text-g-text transition outline-none placeholder:text-g-muted focus:border-transparent focus:outline-2 focus:-outline-offset-1 focus:outline-g-accent"
82
- />
83
- {errors.email && <p className="mt-1 text-sm text-g-danger">{errors.email}</p>}
84
- </div>
85
-
86
- <div>
87
- <label htmlFor={passwordId} className="block text-sm font-bold text-g-heading">
88
- Password
89
- </label>
90
- <input
91
- id={passwordId}
92
- type="password"
93
- value={form.data.password}
94
- onChange={(event) => form.setData('password', event.target.value)}
95
- required
96
- className="mt-1 w-full rounded-g-ctl border border-g-line-strong bg-g-panel px-3 py-2 text-g-text transition outline-none placeholder:text-g-muted focus:border-transparent focus:outline-2 focus:-outline-offset-1 focus:outline-g-accent"
97
- />
98
- {errors.password && <p className="mt-1 text-sm text-g-danger">{errors.password}</p>}
99
- </div>
100
-
101
- <div>
102
- <label htmlFor={passwordConfirmationId} className="block text-sm font-bold text-g-heading">
103
- Confirm password
104
- </label>
105
- <input
106
- id={passwordConfirmationId}
107
- type="password"
108
- value={form.data.passwordConfirmation}
109
- onChange={(event) => form.setData('passwordConfirmation', event.target.value)}
110
- required
111
- className="mt-1 w-full rounded-g-ctl border border-g-line-strong bg-g-panel px-3 py-2 text-g-text transition outline-none placeholder:text-g-muted focus:border-transparent focus:outline-2 focus:-outline-offset-1 focus:outline-g-accent"
112
- />
113
- {errors.passwordConfirmation && (
114
- <p className="mt-1 text-sm text-g-danger">{errors.passwordConfirmation}</p>
115
- )}
116
- </div>
117
-
118
- <button
119
- type="submit"
120
- disabled={form.processing}
121
- className="w-full rounded-g-ctl bg-g-accent px-4 py-2 text-sm font-bold text-g-on-accent transition hover:bg-g-accent-down disabled:cursor-not-allowed disabled:opacity-45"
122
- >
33
+ <form className="mt-6 space-y-4" onSubmit={form.handleSubmit}>
34
+ <Field form={form} name="name" />
35
+ <Field form={form} name="email" />
36
+ <Field form={form} name="password" as="password" />
37
+ <Field form={form} name="passwordConfirmation" as="password" label="Confirm password" />
38
+ <Button type="submit" disabled={form.processing} block>
123
39
  Create account
124
- </button>
40
+ </Button>
125
41
  </form>
126
42
 
127
43
  <p className="mt-6 text-center text-sm text-g-text-2">
@@ -1,4 +1,5 @@
1
1
  import Layout from '../../components/Layout.js'
2
+ import { Alert } from '@/resources/js/components/ui/Alert'
2
3
 
3
4
  interface Props {
4
5
  user?: { id: number; name: string; email: string } | null
@@ -22,10 +23,7 @@ export default function Dashboard({ user }: Props) {
22
23
  <p className="mt-2 text-sm text-g-text-2">Email: {user.email}</p>
23
24
  </div>
24
25
  ) : (
25
- <p className="flex gap-3 border-y border-g-line py-2.5 text-sm">
26
- <span className="w-10 shrink-0 text-right font-mono text-xs font-bold leading-5 text-g-danger">error</span>
27
- <span className="text-g-text">You are not signed in.</span>
28
- </p>
26
+ <Alert tone="danger">You are not signed in.</Alert>
29
27
  )}
30
28
  </section>
31
29
  </Layout>
@@ -1,6 +1,10 @@
1
- import { Head, useForm } from '@inertiajs/react'
2
- import { useId, type FormEvent } from 'react'
1
+ import { Head } from '@inertiajs/react'
2
+ import { useRouteForm } from '@guren/inertia-client/forms'
3
3
  import Layout from '../../components/Layout.js'
4
+ import { profileUpdateForm } from '@/.guren/forms.gen'
5
+ import { Alert } from '@/resources/js/components/ui/Alert'
6
+ import { Button } from '@/resources/js/components/ui/Button'
7
+ import { Field } from '@/resources/js/components/ui/Field'
4
8
  import type { ValidationErrors } from '@guren/core'
5
9
 
6
10
  interface Props {
@@ -9,27 +13,8 @@ interface Props {
9
13
  status?: string
10
14
  }
11
15
 
12
- type ProfileFormValues = {
13
- name: string
14
- email: string
15
- password: string
16
- }
17
-
18
16
  export default function ProfileEdit({ profile, status }: Props) {
19
- const form = useForm<ProfileFormValues>({
20
- name: profile.name,
21
- email: profile.email,
22
- password: '',
23
- })
24
-
25
- const nameId = useId()
26
- const emailId = useId()
27
- const passwordId = useId()
28
-
29
- const handleSubmit = (event: FormEvent<HTMLFormElement>) => {
30
- event.preventDefault()
31
- form.put('/profile')
32
- }
17
+ const form = useRouteForm(profileUpdateForm, { name: profile.name, email: profile.email, password: '' })
33
18
 
34
19
  return (
35
20
  <Layout>
@@ -44,62 +29,16 @@ export default function ProfileEdit({ profile, status }: Props) {
44
29
  </header>
45
30
 
46
31
  {status ? (
47
- <p className="flex gap-3 border-y border-g-line py-2.5 text-sm">
48
- <span className="w-10 shrink-0 text-right font-mono text-xs font-bold leading-5 text-g-ok">ok</span>
49
- <span className="text-g-text">{status}</span>
50
- </p>
32
+ <Alert>{status}</Alert>
51
33
  ) : null}
52
34
 
53
- <form className="space-y-4" onSubmit={handleSubmit}>
54
- <div>
55
- <label htmlFor={nameId} className="block text-sm font-bold text-g-heading">
56
- Name
57
- </label>
58
- <input
59
- id={nameId}
60
- type="text"
61
- value={form.data.name}
62
- onChange={(event) => form.setData('name', event.target.value)}
63
- className="mt-1 w-full rounded-g-ctl border border-g-line-strong bg-g-panel px-3 py-2 text-g-text transition outline-none placeholder:text-g-muted focus:border-transparent focus:outline-2 focus:-outline-offset-1 focus:outline-g-accent"
64
- />
65
- {form.errors.name ? <p className="mt-1 text-sm text-g-danger">{form.errors.name}</p> : null}
66
- </div>
67
-
68
- <div>
69
- <label htmlFor={emailId} className="block text-sm font-bold text-g-heading">
70
- Email
71
- </label>
72
- <input
73
- id={emailId}
74
- type="email"
75
- value={form.data.email}
76
- onChange={(event) => form.setData('email', event.target.value)}
77
- className="mt-1 w-full rounded-g-ctl border border-g-line-strong bg-g-panel px-3 py-2 text-g-text transition outline-none placeholder:text-g-muted focus:border-transparent focus:outline-2 focus:-outline-offset-1 focus:outline-g-accent"
78
- />
79
- {form.errors.email ? <p className="mt-1 text-sm text-g-danger">{form.errors.email}</p> : null}
80
- </div>
81
-
82
- <div>
83
- <label htmlFor={passwordId} className="block text-sm font-bold text-g-heading">
84
- New password
85
- </label>
86
- <input
87
- id={passwordId}
88
- type="password"
89
- value={form.data.password}
90
- onChange={(event) => form.setData('password', event.target.value)}
91
- className="mt-1 w-full rounded-g-ctl border border-g-line-strong bg-g-panel px-3 py-2 text-g-text transition outline-none placeholder:text-g-muted focus:border-transparent focus:outline-2 focus:-outline-offset-1 focus:outline-g-accent"
92
- />
93
- {form.errors.password ? <p className="mt-1 text-sm text-g-danger">{form.errors.password}</p> : null}
94
- </div>
95
-
96
- <button
97
- type="submit"
98
- disabled={form.processing}
99
- className="w-full rounded-g-ctl bg-g-accent px-4 py-2 text-sm font-bold text-g-on-accent transition hover:bg-g-accent-down disabled:cursor-not-allowed disabled:opacity-45"
100
- >
35
+ <form className="space-y-4" onSubmit={form.handleSubmit}>
36
+ <Field form={form} name="name" />
37
+ <Field form={form} name="email" />
38
+ <Field form={form} name="password" as="password" label="New password" />
39
+ <Button type="submit" disabled={form.processing} block>
101
40
  Save changes
102
- </button>
41
+ </Button>
103
42
  </form>
104
43
  </section>
105
44
  </Layout>
@@ -4,20 +4,23 @@ import RegisterController from '../app/Http/Controllers/Auth/RegisterController.
4
4
  import DashboardController from '../app/Http/Controllers/DashboardController.js'
5
5
  import ProfileController from '../app/Http/Controllers/ProfileController.js'
6
6
  import { throttleLogin, throttleRegistration } from '../app/Http/Middleware/AuthThrottle.js'
7
+ import { LoginSchema } from '../app/Http/Validators/LoginValidator.js'
8
+ import { ProfileUpdateSchema } from '../app/Http/Validators/ProfileValidator.js'
9
+ import { RegisterSchema } from '../app/Http/Validators/RegisterValidator.js'
7
10
 
8
11
  // Uses the 'auth' and 'guest' aliases routes/web.ts registers on this router.
9
12
  export function registerAuthRoutes(router: Router<'auth' | 'guest'>): void {
10
13
  router.middleware('guest').group((guest) => {
11
14
  guest.get('/login', [LoginController, 'show']).name('login')
12
- guest.post('/login', [LoginController, 'store'], throttleLogin).name('login.store')
15
+ guest.post('/login', { name: 'login.store', body: LoginSchema, middlewares: [throttleLogin] }, [LoginController, 'store'])
13
16
  guest.get('/register', [RegisterController, 'show']).name('register')
14
- guest.post('/register', [RegisterController, 'store'], throttleRegistration).name('register.store')
17
+ guest.post('/register', { name: 'register.store', body: RegisterSchema, middlewares: [throttleRegistration] }, [RegisterController, 'store'])
15
18
  })
16
19
 
17
20
  router.middleware('auth').group((authed) => {
18
21
  authed.post('/logout', [LoginController, 'destroy']).name('logout')
19
22
  authed.get('/dashboard', [DashboardController, 'index']).name('dashboard')
20
23
  authed.get('/profile', [ProfileController, 'edit']).name('profile.edit')
21
- authed.put('/profile', [ProfileController, 'update']).name('profile.update')
24
+ authed.put('/profile', { name: 'profile.update', body: ProfileUpdateSchema }, [ProfileController, 'update'])
22
25
  })
23
26
  }
@@ -24,6 +24,13 @@
24
24
  // `env` a config definition receives. bin/ and drizzle.config.ts run outside the app.
25
25
  "files": ["app/**", "config/**", "routes/**", "src/**", "modules/*/**"],
26
26
  "rules": { "guren/no-unvalidated-env-read": "error" }
27
+ },
28
+ {
29
+ // Pages and components style with the Guren UI tokens in resources/css/guren.css
30
+ // (bg-g-panel, text-g-text, var(--g-accent)), which carry the dark theme; a
31
+ // palette class or a hex literal does not.
32
+ "files": ["resources/js/**"],
33
+ "rules": { "guren/no-raw-color": "error" }
27
34
  }
28
35
  ]
29
36
  // Type-aware rules (typescript/no-floating-promises and friends) need
@@ -22,9 +22,9 @@
22
22
  "db:seed": "bunx guren db:seed"
23
23
  },
24
24
  "dependencies": {
25
- "@guren/cli": "^2.32.0",
25
+ "@guren/cli": "^2.33.0",
26
26
  "@guren/core": "^1.25.0",
27
- "@guren/inertia-client": "^1.2.2",
27
+ "@guren/inertia-client": "^1.3.0",
28
28
  "@guren/orm": "^2.15.0",
29
29
  "@inertiajs/react": "^3.6.1",
30
30
  "drizzle-orm": "1.0.0-rc.4",
@@ -1,3 +1,4 @@
1
+ /* guren:tokens begin: `guren upgrade` replaces everything up to the end marker. Add your own rules after it. */
1
2
  /* Guren UI — design tokens (https://github.com/gurenjs/guren-ui)
2
3
  Light is the guren.dev docs light theme (white + crimson); dark is its
3
4
  docs dark theme (rose-pine-moon ground, rose accent text). The dark block
@@ -137,3 +138,4 @@
137
138
  --shadow-g-card: var(--g-shadow-card);
138
139
  --shadow-g-float: var(--g-shadow-float);
139
140
  }
141
+ /* guren:tokens end */
@@ -0,0 +1,29 @@
1
+ // guren-ui: Alert v1. `guren upgrade` replaces this file only while it is unedited.
2
+ import type { HTMLAttributes } from 'react'
3
+
4
+ export type AlertTone = 'ok' | 'warn' | 'danger'
5
+
6
+ const KEYS: Record<AlertTone, { text: string; color: string }> = {
7
+ ok: { text: 'ok', color: 'text-g-ok' },
8
+ warn: { text: 'warn', color: 'text-g-warn' },
9
+ danger: { text: 'error', color: 'text-g-danger' },
10
+ }
11
+
12
+ export interface AlertProps extends HTMLAttributes<HTMLDivElement> {
13
+ tone?: AlertTone
14
+ }
15
+
16
+ /** A message as a diagnostic row: the tone as a mono key in a fixed gutter, a hairline, the body. */
17
+ export function Alert({ tone = 'ok', className, children, ...props }: AlertProps) {
18
+ const key = KEYS[tone]
19
+ return (
20
+ <div
21
+ role={tone === 'danger' ? 'alert' : 'status'}
22
+ className={['flex gap-3 border-y border-g-line py-2.5 text-sm', className].filter(Boolean).join(' ')}
23
+ {...props}
24
+ >
25
+ <span className={`w-10 shrink-0 text-right font-mono text-xs font-bold leading-5 ${key.color}`}>{key.text}</span>
26
+ <span className="text-g-text">{children}</span>
27
+ </div>
28
+ )
29
+ }
@@ -0,0 +1,46 @@
1
+ // guren-ui: Button v1. `guren upgrade` replaces this file only while it is unedited.
2
+ import type { ButtonHTMLAttributes } from 'react'
3
+
4
+ export type ButtonVariant = 'primary' | 'secondary' | 'danger' | 'ghost'
5
+ export type ButtonSize = 'md' | 'sm'
6
+
7
+ export interface ButtonClassOptions {
8
+ variant?: ButtonVariant
9
+ size?: ButtonSize
10
+ /** Full width, for a form's one submit. */
11
+ block?: boolean
12
+ className?: string
13
+ }
14
+
15
+ // Whole strings rather than fragments, so a class can be found by searching for it.
16
+ const CLASSES: Record<ButtonVariant, Record<ButtonSize, string>> = {
17
+ primary: {
18
+ md: 'rounded-g-ctl bg-g-accent px-4 py-2 text-sm font-bold text-g-on-accent transition hover:bg-g-accent-down',
19
+ sm: 'rounded-g-ctl bg-g-accent px-3 py-1 text-sm font-bold text-g-on-accent transition hover:bg-g-accent-down',
20
+ },
21
+ secondary: {
22
+ md: 'rounded-g-ctl border border-g-line-strong bg-g-panel px-4 py-2 text-sm font-bold text-g-text transition hover:border-g-muted',
23
+ sm: 'rounded-g-ctl border border-g-line-strong bg-g-panel px-3 py-1 text-sm font-bold text-g-text transition hover:border-g-muted',
24
+ },
25
+ danger: {
26
+ md: 'rounded-g-ctl border border-g-danger-chip px-4 py-2 text-sm font-bold text-g-danger transition hover:bg-g-danger-tint',
27
+ sm: 'rounded-g-ctl border border-g-danger-chip px-3 py-1 text-sm font-bold text-g-danger transition hover:bg-g-danger-tint',
28
+ },
29
+ ghost: {
30
+ md: 'rounded-g-ctl px-4 py-2 text-sm font-bold text-g-accent-text transition hover:bg-g-accent-tint',
31
+ sm: 'rounded-g-ctl px-3 py-1 text-sm font-bold text-g-accent-text transition hover:bg-g-accent-tint',
32
+ },
33
+ }
34
+
35
+ /** The classes of a button, for an element that is not one: an Inertia `<Link>` or an `<a>`. */
36
+ export function buttonClass({ variant = 'primary', size = 'md', block = false, className }: ButtonClassOptions = {}): string {
37
+ return [block && 'w-full', CLASSES[variant][size], 'disabled:cursor-not-allowed disabled:opacity-45', className]
38
+ .filter(Boolean)
39
+ .join(' ')
40
+ }
41
+
42
+ export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement>, Omit<ButtonClassOptions, 'className'> {}
43
+
44
+ export function Button({ variant, size, block, className, type = 'button', ...props }: ButtonProps) {
45
+ return <button type={type} className={buttonClass({ variant, size, block, className })} {...props} />
46
+ }
@@ -0,0 +1,17 @@
1
+ // guren-ui: Card v1. `guren upgrade` replaces this file only while it is unedited.
2
+ import type { HTMLAttributes, ReactNode } from 'react'
3
+
4
+ export interface CardProps extends Omit<HTMLAttributes<HTMLElement>, 'title'> {
5
+ /** `article` for one item of a list. */
6
+ as?: 'section' | 'article' | 'div'
7
+ title?: ReactNode
8
+ }
9
+
10
+ export function Card({ as: Element = 'section', title, className, children, ...props }: CardProps) {
11
+ return (
12
+ <Element className={['rounded-g-card border border-g-line bg-g-panel p-4 shadow-g-card', className].filter(Boolean).join(' ')} {...props}>
13
+ {title ? <h2 className="mb-3 text-lg font-bold text-g-heading">{title}</h2> : null}
14
+ {children}
15
+ </Element>
16
+ )
17
+ }
@@ -0,0 +1,17 @@
1
+ // guren-ui: Checkbox v1. `guren upgrade` replaces this file only while it is unedited.
2
+ import type { InputHTMLAttributes, ReactNode } from 'react'
3
+
4
+ export interface CheckboxProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'type'> {
5
+ /** The text beside the box; the wrapping `<label>` makes it the box's accessible name. */
6
+ label: ReactNode
7
+ }
8
+
9
+ /** `className` goes to the wrapping `<label>`; every other prop to the `<input>`. */
10
+ export function Checkbox({ label, className, ...props }: CheckboxProps) {
11
+ return (
12
+ <label className={['flex items-center gap-2', className].filter(Boolean).join(' ')}>
13
+ <input type="checkbox" className="h-4 w-4 rounded accent-g-accent" {...props} />
14
+ {label}
15
+ </label>
16
+ )
17
+ }
@@ -0,0 +1,68 @@
1
+ // guren-ui: Field v1. `guren upgrade` replaces this file only while it is unedited.
2
+ import type { ReactNode } from 'react'
3
+ import { useField, type FieldInput, type FieldOption, type FieldState, type FormDataType } from '@guren/inertia-client/forms'
4
+ import { Checkbox } from './Checkbox'
5
+ import { Input } from './Input'
6
+ import { Label } from './Label'
7
+ import { Select } from './Select'
8
+ import { Textarea } from './Textarea'
9
+
10
+ export interface FieldProps<TBody extends FormDataType<TBody>, K extends keyof TBody & string> {
11
+ form: Parameters<typeof useField<TBody, K>>[0]
12
+ name: K
13
+ label?: string
14
+ as?: FieldInput
15
+ hint?: string
16
+ options?: FieldOption<TBody[K]>[]
17
+ /** For a file input: submit every chosen file instead of the first. */
18
+ multiple?: boolean
19
+ className?: string
20
+ /** Renders the control in place of the default one; the label, hint and error stay. */
21
+ children?: (field: FieldState<TBody[K]>) => ReactNode
22
+ }
23
+
24
+ /** One form key: its label, its control, a hint and the server's error, wired by `useField`. */
25
+ export function Field<TBody extends FormDataType<TBody>, K extends keyof TBody & string>({
26
+ form,
27
+ name,
28
+ className,
29
+ children,
30
+ ...overrides
31
+ }: FieldProps<TBody, K>) {
32
+ const field = useField(form, name, overrides)
33
+ if (field.input === 'hidden') return <input {...field.control} />
34
+
35
+ return (
36
+ <div className={className}>
37
+ {field.input === 'checkbox' && !children ? <FieldCheckbox field={field} /> : <Label htmlFor={field.id}>{field.label}</Label>}
38
+ {children ? children(field) : <FieldControl field={field} />}
39
+ {field.hint && <p id={field.hintId} className="mt-1 text-sm text-g-text-2">{field.hint}</p>}
40
+ {field.error && <p id={field.errorId} className="mt-1 text-sm text-g-danger">{field.error}</p>}
41
+ </div>
42
+ )
43
+ }
44
+
45
+ function FieldCheckbox<TValue>({ field }: { field: Extract<FieldState<TValue>, { input: 'checkbox' }> }) {
46
+ const { type: _type, ...control } = field.control
47
+ return <Checkbox {...control} label={field.label} />
48
+ }
49
+
50
+ function FieldControl<TValue>({ field }: { field: FieldState<TValue> }) {
51
+ switch (field.input) {
52
+ case 'checkbox':
53
+ case 'hidden':
54
+ return null
55
+ case 'textarea':
56
+ return <Textarea {...field.control} className="mt-1" />
57
+ case 'select':
58
+ return (
59
+ <Select
60
+ {...field.control}
61
+ className="mt-1"
62
+ options={[{ value: '', label: '' }, ...field.options.map((option, index) => ({ value: String(index), label: option.label }))]}
63
+ />
64
+ )
65
+ default:
66
+ return <Input {...field.control} className="mt-1" />
67
+ }
68
+ }
@@ -0,0 +1,10 @@
1
+ // guren-ui: Input v1. `guren upgrade` replaces this file only while it is unedited.
2
+ import type { InputHTMLAttributes } from 'react'
3
+
4
+ export const INPUT_CLASS =
5
+ 'w-full rounded-g-ctl border border-g-line-strong bg-g-panel px-3 py-2 text-g-text transition outline-none placeholder:text-g-muted focus:border-transparent focus:outline-2 focus:-outline-offset-1 focus:outline-g-accent aria-invalid:border-g-danger-chip'
6
+
7
+ /** `aria-invalid` turns the border to the danger tone. */
8
+ export function Input({ className, ...props }: InputHTMLAttributes<HTMLInputElement>) {
9
+ return <input className={[INPUT_CLASS, className].filter(Boolean).join(' ')} {...props} />
10
+ }
@@ -0,0 +1,6 @@
1
+ // guren-ui: Label v1. `guren upgrade` replaces this file only while it is unedited.
2
+ import type { LabelHTMLAttributes } from 'react'
3
+
4
+ export function Label({ className, ...props }: LabelHTMLAttributes<HTMLLabelElement>) {
5
+ return <label className={['block text-sm font-bold text-g-heading', className].filter(Boolean).join(' ')} {...props} />
6
+ }
@@ -0,0 +1,29 @@
1
+ // guren-ui: Select v1. `guren upgrade` replaces this file only while it is unedited.
2
+ import type { SelectHTMLAttributes } from 'react'
3
+
4
+ const SELECT_CLASS =
5
+ 'w-full rounded-g-ctl border border-g-line-strong bg-g-panel px-3 py-2 text-g-text transition outline-none focus:border-transparent focus:outline-2 focus:-outline-offset-1 focus:outline-g-accent aria-invalid:border-g-danger-chip'
6
+
7
+ export interface SelectOption {
8
+ value: string
9
+ label: string
10
+ }
11
+
12
+ export interface SelectProps extends SelectHTMLAttributes<HTMLSelectElement> {
13
+ /** Rendered as `<option>` elements ahead of any children. */
14
+ options?: readonly SelectOption[]
15
+ }
16
+
17
+ /** `aria-invalid` turns the border to the danger tone. */
18
+ export function Select({ options, className, children, ...props }: SelectProps) {
19
+ return (
20
+ <select className={[SELECT_CLASS, className].filter(Boolean).join(' ')} {...props}>
21
+ {options?.map((option) => (
22
+ <option key={option.value} value={option.value}>
23
+ {option.label}
24
+ </option>
25
+ ))}
26
+ {children}
27
+ </select>
28
+ )
29
+ }
@@ -0,0 +1,10 @@
1
+ // guren-ui: Textarea v1. `guren upgrade` replaces this file only while it is unedited.
2
+ import type { TextareaHTMLAttributes } from 'react'
3
+
4
+ const TEXTAREA_CLASS =
5
+ 'w-full rounded-g-ctl border border-g-line-strong bg-g-panel px-3 py-2 text-g-text transition outline-none placeholder:text-g-muted focus:border-transparent focus:outline-2 focus:-outline-offset-1 focus:outline-g-accent aria-invalid:border-g-danger-chip'
6
+
7
+ /** `aria-invalid` turns the border to the danger tone. */
8
+ export function Textarea({ className, ...props }: TextareaHTMLAttributes<HTMLTextAreaElement>) {
9
+ return <textarea className={[TEXTAREA_CLASS, className].filter(Boolean).join(' ')} {...props} />
10
+ }
@@ -1,4 +1,6 @@
1
1
  import { Head } from '@inertiajs/react'
2
+ import { buttonClass } from '@/resources/js/components/ui/Button'
3
+
2
4
  interface Props {
3
5
  message: string
4
6
  }
@@ -36,13 +38,13 @@ export default function Home({ message }: Props) {
36
38
  <div className="mb-12 flex flex-wrap gap-3">
37
39
  <a
38
40
  href="https://guren.dev/docs"
39
- className="inline-flex items-center rounded-g-ctl bg-g-accent px-4 py-2 text-sm font-bold text-g-on-accent transition hover:bg-g-accent-down"
41
+ className={buttonClass({ className: 'inline-flex items-center' })}
40
42
  >
41
43
  Documentation
42
44
  </a>
43
45
  <a
44
46
  href="https://github.com/gurenjs/guren"
45
- className="inline-flex items-center rounded-g-ctl border border-g-line-strong bg-g-panel px-4 py-2 text-sm font-bold text-g-text transition hover:border-g-muted"
47
+ className={buttonClass({ variant: 'secondary', className: 'inline-flex items-center' })}
46
48
  >
47
49
  GitHub
48
50
  </a>