Skip to content

Commit e405014

Browse files
authored
feat: update Next.js generator style with tailwind (#348)
1 parent cfc4d69 commit e405014

File tree

8 files changed

+126
-76
lines changed

8 files changed

+126
-76
lines changed

templates/next/components/common/Pagination.tsx

+47-22
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,53 @@ const Pagination = ({ collection }: Props) => {
1717
} = view;
1818

1919
return (
20-
<nav aria-label="Page navigation">
21-
<Link href={first ? first : '#'}>
22-
<a className={`btn btn-primary${previous ? '' : ' disabled'}`} aria-label="First page">
23-
<span aria-hidden="true">&lArr;</span> First
24-
</a>
25-
</Link>
26-
<Link href={previous ? previous : '#'}>
27-
<a className={`btn btn-primary${previous ? '' : ' disabled'}`} aria-label="Previous page">
28-
<span aria-hidden="true">&larr;</span> Previous
29-
</a>
30-
</Link>
31-
<Link href={next ? next : '#'}>
32-
<a className={`btn btn-primary${next ? '' : ' disabled'}`} aria-label="Next page">
33-
Next <span aria-hidden="true">&rarr;</span>
34-
</a>
35-
</Link>
36-
<Link href={last ? last : '#'}>
37-
<a className={`btn btn-primary${next ? '' : ' disabled'}`} aria-label="Last page">
38-
Last <span aria-hidden="true">&rArr;</span>
39-
</a>
40-
</Link>
41-
</nav>
20+
<div className="text-center">
21+
<nav
22+
className="text-xs font-bold inline-flex mx-auto divide-x-2 divide-gray-200 flex-row flex-wrap items-center justify-center mb-4 border-2 border-gray-200 rounded-2xl overflow-hidden"
23+
aria-label="Page navigation"
24+
>
25+
<Link href={first ? first : "#"}>
26+
<a
27+
className={`text-black p-3 hover:text-cyan-500 hover:bg-cyan-50 ${
28+
previous ? "" : " text-gray-500 pointer-events-none"
29+
}`}
30+
aria-label="First page"
31+
>
32+
<span aria-hidden="true">&lArr;</span> First
33+
</a>
34+
</Link>
35+
<Link href={previous ? previous : "#"}>
36+
<a
37+
className={`text-black p-3 hover:text-cyan-500 hover:bg-cyan-50 ${
38+
previous ? "" : " text-gray-500 pointer-events-none"
39+
}`}
40+
aria-label="Previous page"
41+
>
42+
<span aria-hidden="true">&larr;</span> Previous
43+
</a>
44+
</Link>
45+
<Link href={next ? next : "#"}>
46+
<a
47+
className={`text-black p-3 hover:text-cyan-500 hover:bg-cyan-50 ${
48+
next ? "" : " text-gray-500 pointer-events-none"
49+
}`}
50+
aria-label="Next page"
51+
>
52+
Next <span aria-hidden="true">&rarr;</span>
53+
</a>
54+
</Link>
55+
<Link href={last ? last : "#"}>
56+
<a
57+
className={`text-black p-3 hover:text-cyan-500 hover:bg-cyan-50 ${
58+
next ? "" : "text-gray-500 pointer-events-none"
59+
}`}
60+
aria-label="Last page"
61+
>
62+
Last <span aria-hidden="true">&rArr;</span>
63+
</a>
64+
</Link>
65+
</nav>
66+
</div>
4267
);
4368
};
4469

templates/next/components/common/ReferenceLinks.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const ReferenceLinks: FunctionComponent<Props> = ({ items }) => {
2020

2121
return (
2222
<Link href={typeof items === "string" ? items : items.href}>
23-
<a>
23+
<a className="text-cyan-700 font-bold">
2424
{typeof items === "string" ? items : items.name}
2525
</a>
2626
</Link>

templates/next/components/foo/Form.tsx

+23-17
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,15 @@ export const Form: FunctionComponent<Props> = ({ {{{lc}}} }) => {
5050
};
5151

5252
return (
53-
<div>
54-
<h1>{ {{{lc}}} ? `Edit {{{ucf}}} ${ {{~lc}}['@id']}` : `Create {{{ucf}}}` }</h1>
53+
<div className="container mx-auto px-4 max-w-2xl mt-4">
54+
<Link href="/{{{lc}}}s">
55+
<a className="text-sm text-cyan-500 font-bold hover:text-cyan-700">
56+
{`< Back to list`}
57+
</a>
58+
</Link>
59+
<h1 className="text-3xl my-2">
60+
{ {{{lc}}} ? `Edit {{{ucf}}} ${ {{~lc}}['@id']}` : `Create {{{ucf}}}` }
61+
</h1>
5562
<Formik
5663
initialValues={
5764
{{lc}} ?
@@ -110,15 +117,15 @@ export const Form: FunctionComponent<Props> = ({ {{{lc}}} }) => {
110117
handleSubmit,
111118
isSubmitting,
112119
}) => (
113-
<form onSubmit={handleSubmit}>
120+
<form className="shadow-md p-4" onSubmit={handleSubmit}>
114121
{{#each formFields}}
115-
<div className="form-group">
122+
<div className="mb-2">
116123
{{#if isRelations}}
117-
<div className="form-control-label">{{name}}</div>
124+
<div className="text-gray-700 block text-sm font-bold">{{name}}</div>
118125
<FieldArray
119126
name="{{name}}"
120127
render={(arrayHelpers) => (
121-
<div id="{{../lc}}_{{name}}">
128+
<div className="mb-2" id="{{../lc}}_{{name}}">
122129
{values.{{name}} && values.{{name}}.length > 0 ? (
123130
values.{{name}}.map((item: any, index: number) => (
124131
<div key={index}>
@@ -146,7 +153,7 @@ export const Form: FunctionComponent<Props> = ({ {{{lc}}} }) => {
146153
)}
147154
/>
148155
{{else}}
149-
<label className="form-control-label" htmlFor="{{../lc}}_{{name}}">{{name}}</label>
156+
<label className="text-gray-700 block text-sm font-bold" htmlFor="{{../lc}}_{{name}}">{{name}}</label>
150157
<input
151158
name="{{name}}"
152159
id="{{../lc}}_{{name}}"
@@ -160,13 +167,13 @@ export const Form: FunctionComponent<Props> = ({ {{{lc}}} }) => {
160167
{{#if step}}step="{{{step}}}"{{/if}}
161168
placeholder="{{{description}}}"
162169
{{#if required}}required={true}{{/if}}
163-
className={`form-control${errors.{{name}} && touched.{{name}} ? ' is-invalid' : ''}`}
170+
className={`mt-1 block w-full ${errors.{{name}} && touched.{{name}} ? 'border-red-500' : ''}`}
164171
aria-invalid={errors.{{name}} && touched.{{name~}} ? 'true' : undefined}
165172
onChange={handleChange}
166173
onBlur={handleBlur}
167174
/>
168175
<ErrorMessage
169-
className="invalid-feedback"
176+
className="text-xs text-red-500 pt-1"
170177
component="div"
171178
name="{{name}}"
172179
/>
@@ -175,8 +182,8 @@ export const Form: FunctionComponent<Props> = ({ {{{lc}}} }) => {
175182
{{/each}}
176183
{status && status.msg && (
177184
<div
178-
className={`alert ${
179-
status.isValid ? "alert-success" : "alert-danger"
185+
className={`border px-4 py-3 my-4 rounded ${
186+
status.isValid ? "text-cyan-700 border-cyan-500 bg-cyan-200/50" : "text-red-700 border-red-400 bg-red-100"
180187
}`}
181188
role="alert"
182189
>
@@ -185,22 +192,21 @@ export const Form: FunctionComponent<Props> = ({ {{{lc}}} }) => {
185192
)}
186193
<button
187194
type="submit"
188-
className="btn btn-success"
195+
className="inline-block mt-2 bg-cyan-500 hover:bg-cyan-700 text-sm text-white font-bold py-2 px-4 rounded"
189196
disabled={isSubmitting}
190197
>
191198
Submit
192199
</button>
193200
</form>
194201
)}
195202
</Formik>
196-
<Link href="/{{{lc}}}s">
197-
<a className="btn btn-primary">Back to list</a>
198-
</Link>
203+
<div className="flex space-x-2 mt-4 justify-end">
199204
{ {{{lc}}} && (
200-
<button className="btn btn-danger" onClick={handleDelete}>
201-
<a>Delete</a>
205+
<button className="inline-block mt-2 border-2 border-red-400 hover:border-red-700 hover:text-red-700 text-sm text-red-400 font-bold py-2 px-4 rounded" onClick={handleDelete}>
206+
Delete
202207
</button>
203208
)}
209+
</div>
204210
</div>
205211
);
206212
};

templates/next/components/foo/List.tsx

+28-18
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,29 @@ interface Props {
1010
}
1111

1212
export const List: FunctionComponent<Props> = ({ {{{lc}}}s }) => (
13-
<div>
14-
<h1>{{{ucf}}} List</h1>
15-
<Link href="/{{{lc}}}s/create">
16-
<a className="btn btn-primary">Create</a>
17-
</Link>
18-
<table className="table table-responsive table-striped table-hover">
19-
<thead>
13+
<div className="p-4">
14+
<div className="flex justify-between items-center">
15+
<h1 className="text-3xl mb-2">{{{ucf}}} List</h1>
16+
<Link href="/{{{lc}}}s/create">
17+
<a className="bg-cyan-500 hover:bg-cyan-700 text-white text-sm font-bold py-2 px-4 rounded">
18+
Create
19+
</a>
20+
</Link>
21+
</div>
22+
<table cellPadding={10} className="shadow-md table border-collapse min-w-full leading-normal table-auto text-left my-3">
23+
<thead className="w-full text-xs uppercase font-light text-gray-700 bg-gray-200 py-2 px-4">
2024
<tr>
2125
<th>id</th>
2226
{{#each fields}}
2327
<th>{{name}}</th>
2428
{{/each}}
25-
<th/>
29+
<th colSpan={2} />
2630
</tr>
2731
</thead>
28-
<tbody>
32+
<tbody className="text-sm divide-y divide-gray-200">
2933
{ {{{lc}}}s && ({{{lc}}}s.length !== 0) && {{{lc}}}s.map( ( {{{lc}}} ) => (
3034
{{{lc}}}['@id'] &&
31-
<tr key={ {{{lc}}}['@id'] }>
35+
<tr className="py-2" key={ {{{lc}}}['@id'] }>
3236
<th scope="row">
3337
<ReferenceLinks items={ { href: getPath({{{lc}}}['@id'], '/{{{lc}}}s/[id]'), name: {{{lc}}}['@id'] } } />
3438
</th>
@@ -49,19 +53,25 @@ export const List: FunctionComponent<Props> = ({ {{{lc}}}s }) => (
4953
{{/if}}
5054
</td>
5155
{{/each}}
52-
<td>
56+
<td className="w-8">
5357
<Link href={ getPath({{{lc}}}['@id'], '/{{{lc}}}s/[id]') }>
54-
<a>
55-
<i className="bi bi-search" aria-hidden="true"></i>
56-
<span className="sr-only">Show</span>
58+
<a className="text-cyan-500">
59+
Show
60+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" className="w-6 h-6">
61+
<path d="M12 15a3 3 0 100-6 3 3 0 000 6z" />
62+
<path fillRule="evenodd" d="M1.323 11.447C2.811 6.976 7.028 3.75 12.001 3.75c4.97 0 9.185 3.223 10.675 7.69.12.362.12.752 0 1.113-1.487 4.471-5.705 7.697-10.677 7.697-4.97 0-9.186-3.223-10.675-7.69a1.762 1.762 0 010-1.113zM17.25 12a5.25 5.25 0 11-10.5 0 5.25 5.25 0 0110.5 0z" clipRule="evenodd" />
63+
</svg>
5764
</a>
5865
</Link>
5966
</td>
60-
<td>
67+
<td className="w-8">
6168
<Link href={ getPath({{{lc}}}["@id"], '/{{{lc}}}s/[id]/edit') }>
62-
<a>
63-
<i className="bi bi-pen" aria-hidden="true" />
64-
<span className="sr-only">Edit</span>
69+
<a className="text-cyan-500">
70+
Edit
71+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" className="w-6 h-6">
72+
<path d="M21.731 2.269a2.625 2.625 0 00-3.712 0l-1.157 1.157 3.712 3.712 1.157-1.157a2.625 2.625 0 000-3.712zM19.513 8.199l-3.712-3.712-8.4 8.4a5.25 5.25 0 00-1.32 2.214l-.8 2.685a.75.75 0 00.933.933l2.685-.8a5.25 5.25 0 002.214-1.32l8.4-8.4z" />
73+
<path d="M5.25 5.25a3 3 0 00-3 3v10.5a3 3 0 003 3h10.5a3 3 0 003-3V13.5a.75.75 0 00-1.5 0v5.25a1.5 1.5 0 01-1.5 1.5H5.25a1.5 1.5 0 01-1.5-1.5V8.25a1.5 1.5 0 011.5-1.5h5.25a.75.75 0 000-1.5H5.25z" />
74+
</svg>
6575
</a>
6676
</Link>
6777
</td>

templates/next/components/foo/Show.tsx

+24-15
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,25 @@ export const Show: FunctionComponent<Props> = ({ {{{lc}}}, text }) => {
3030
};
3131

3232
return (
33-
<div>
33+
<div className="p-4">
3434
<Head>
3535
<title>{`Show {{{ucf}}} ${ {{~lc}}['@id']}`}</title>
3636
<script type="application/ld+json" dangerouslySetInnerHTML={ { __html: text } } />
3737
</Head>
38-
<h1>{`Show {{{ucf}}} ${ {{~lc}}['@id']}`}</h1>
39-
<table className="table table-responsive table-striped table-hover">
40-
<thead>
38+
<Link href="/{{{lc}}}s">
39+
<a className="text-sm text-cyan-500 font-bold hover:text-cyan-700">
40+
{`< Back to list`}
41+
</a>
42+
</Link>
43+
<h1 className="text-3xl mb-2">{`Show {{{ucf}}} ${ {{~lc}}['@id']}`}</h1>
44+
<table cellPadding={10} className="shadow-md table border-collapse min-w-full leading-normal table-auto text-left my-3">
45+
<thead className="w-full text-xs uppercase font-light text-gray-700 bg-gray-200 py-2 px-4">
4146
<tr>
4247
<th>Field</th>
4348
<th>Value</th>
4449
</tr>
4550
</thead>
46-
<tbody>
51+
<tbody className="text-sm divide-y divide-gray-200">
4752
{{#each fields}}
4853
<tr>
4954
<th scope="row">{{name}}</th>
@@ -67,19 +72,23 @@ export const Show: FunctionComponent<Props> = ({ {{{lc}}}, text }) => {
6772
</tbody>
6873
</table>
6974
{error && (
70-
<div className="alert alert-danger" role="alert">
75+
<div className="border px-4 py-3 my-4 rounded text-red-700 border-red-400 bg-red-100" role="alert">
7176
{error}
7277
</div>
7378
)}
74-
<Link href="/{{{lc}}}s">
75-
<a className="btn btn-primary">Back to list</a>
76-
</Link>{" "}
77-
<Link href={getPath({{{lc}}}["@id"], '/{{{lc}}}s/[id]/edit')}>
78-
<a className="btn btn-warning">Edit</a>
79-
</Link>
80-
<button className="btn btn-danger" onClick={handleDelete}>
81-
Delete
82-
</button>
79+
<div className="flex space-x-2 mt-4 items-center justify-end">
80+
<Link href={getPath({{{lc}}}["@id"], '/{{{lc}}}s/[id]/edit')}>
81+
<a className="inline-block mt-2 border-2 border-cyan-500 bg-cyan-500 hover:border-cyan-700 hover:bg-cyan-700 text-xs text-white font-bold py-2 px-4 rounded">
82+
Edit
83+
</a>
84+
</Link>
85+
<button
86+
className="inline-block mt-2 border-2 border-red-400 hover:border-red-700 hover:text-red-700 text-xs text-red-400 font-bold py-2 px-4 rounded"
87+
onClick={handleDelete}
88+
>
89+
Delete
90+
</button>
91+
</div>
8392
</div>
8493
);
8594
};

tests/create.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ test('resource create', async ({ page, queries: { getByLabelText, getByRole, get
1616
await expect(getByText('reviews')).toBeVisible();
1717

1818
await expect(getByRole('button', { name: 'Submit' })).toBeVisible();
19-
await expect(getByRole('link', { name: 'Back to list' })).toBeVisible();
19+
await expect(getByRole('link', { name: /Back to list/ })).toBeVisible();
2020
});

tests/edit.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ test('resource edit', async ({ page, within, queries: { getAllByRole, getByLabel
3737

3838
await expect(getByRole('button', { name: 'Submit' })).toBeVisible();
3939
await expect(getByRole('button', { name: 'Delete' })).toBeVisible();
40-
await expect(getByRole('link', { name: 'Back to list' })).toBeVisible();
40+
await expect(getByRole('link', { name: /Back to list/ })).toBeVisible();
4141
});

tests/show.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ test('resource show', async ({ page, within, queries: { getAllByRole, getByRole,
3535

3636
await expect(getByRoleWithinRow('rowheader')).toHaveText('isbn');
3737

38-
await expect(getByRole('link', { name: 'Back to list' })).toBeVisible();
38+
await expect(getByRole('link', { name: /Back to list/ })).toBeVisible();
3939
await expect(getByRole('link', { name: 'Edit' })).toBeVisible();
4040
await expect(getByRole('button', { name: 'Delete' })).toBeVisible();
4141
});

0 commit comments

Comments
 (0)