Skip to content

Commit

Permalink
Custom field example (keystonejs#6051)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmatown authored Jul 7, 2021
1 parent 0d06ddc commit e0d1b20
Show file tree
Hide file tree
Showing 12 changed files with 952 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ jobs:
'task-manager.test.ts',
'testing.test.ts',
'with-auth.test.ts',
'custom-field.test.ts',
]
fail-fast: false
steps:
Expand Down
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Each project below demonstrates a Keystone feature you can learn about and exper
- [Virtual field](./virtual-field): Adds virtual fields to the Blog base.
- [Document field](./document-field): Adds document fields to the Blog base.
- [Testing](./testing): Adds tests with `@keystone-next/testing` to the `withAuth()` example.
- [Custom field](./custom-field): Adds a custom `stars` field to the Blog base.

## Running examples

Expand Down
21 changes: 21 additions & 0 deletions examples/custom-field/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## Feature Example - Custom Field

This project demonstrates how to create a custom field that allows users to select a number of stars.
It builds on the [Blog](../blog) starter project.

## Instructions

To run this project, clone the Keystone repository locally then navigate to this directory and run:

```shell
yarn dev
```

This will start the Admin UI at [localhost:3000](http://localhost:3000).
You can use the Admin UI to create items in your database.

You can also access a GraphQL Playground at [localhost:3000/api/graphql](http://localhost:3000/api/graphql), which allows you to directly run GraphQL queries and mutations.

## Stars field

The `stars` fields in the `stars-field` directory shows a custom field that validates that the value is between 0 and some maximum number of stars and shows a radio input to select the number of stars in the Admin UI. The backend for the field type is in `stars-field/index.ts` and the frontend is in `stars-field/views.tsx`.
10 changes: 10 additions & 0 deletions examples/custom-field/keystone.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { config } from '@keystone-next/keystone/schema';
import { lists } from './schema';

export default config({
db: {
provider: 'sqlite',
url: process.env.DATABASE_URL || 'file:./keystone-example.db',
},
lists,
});
25 changes: 25 additions & 0 deletions examples/custom-field/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "@keystone-next/example-custom-field",
"version": "0.0.0",
"private": true,
"license": "MIT",
"scripts": {
"dev": "keystone-next dev",
"start": "keystone-next start",
"build": "keystone-next build"
},
"dependencies": {
"@keystone-next/fields": "^11.0.0",
"@keystone-next/keystone": "^21.0.2",
"@keystone-next/types": "^21.0.1",
"@keystone-ui/fields": "^4.1.2",
"react": "^17.0.2"
},
"devDependencies": {
"typescript": "^4.3.4"
},
"engines": {
"node": "^12.20 || >= 14.13"
},
"repository": "https://github.com/keystonejs/keystone/tree/master/examples/custom-field"
}
Loading

0 comments on commit e0d1b20

Please sign in to comment.