Skip to content

Commit f16aa10

Browse files
committed
feat: reworks all formkit examples to account for new Regenisis theme
1 parent 82e2168 commit f16aa10

File tree

127 files changed

+1218
-1116
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+1218
-1116
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { genesisIcons } from '@formkit/icons'
2+
3+
export default {
4+
theme: 'genesis', // legacy genesis CSS theme
5+
icons: {
6+
...genesisIcons,
7+
},
8+
}
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1+
import { genesisIcons } from "@formkit/icons"
2+
import { rootClasses } from './formkit.theme.js'
13
import { createAutoAnimatePlugin } from '@formkit/addons'
24

35
export default {
46
plugins: [
57
createAutoAnimatePlugin()
6-
]
7-
}
8+
],
9+
icons: {
10+
...genesisIcons
11+
},
12+
config: {
13+
rootClasses
14+
}
15+
}
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
// formkit.config.js
2-
import { defaultConfig } from '@formkit/vue'
1+
import { genesisIcons } from "@formkit/icons"
2+
import { rootClasses } from './formkit.theme.js'
33
import { createAutoHeightTextareaPlugin } from '@formkit/addons'
44

5-
const config = defaultConfig({
5+
export default {
66
plugins: [
77
createAutoHeightTextareaPlugin(),
88
],
9-
})
10-
11-
export default config
9+
icons: {
10+
...genesisIcons
11+
},
12+
config: {
13+
rootClasses
14+
}
15+
}

.examples/autocomplete-pro/autocomplete-full.vue

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,22 @@ async function searchMovies({ search, page, hasNextPage }) {
3939
:options="searchMovies"
4040
selection-appearance="option"
4141
multiple
42+
remove-selection-class="p-2 pl-0"
4243
>
4344
<template #option="{ option }">
44-
<div class="formkit-option">
45-
<div class="image-container">
45+
<div class="flex items-center justify-between">
46+
<div class="image-container w-1/4 mr-2">
4647
<img
4748
:src="`https://image.tmdb.org/t/p/w500${option.poster_path}`"
4849
alt="optionAvatar"
50+
class="w-full"
4951
/>
5052
</div>
51-
<div class="text-container">
52-
<div>
53+
<div class="text-container w-full">
54+
<div class="text-base leading-none font-bold">
5355
{{ option.label }}
5456
</div>
55-
<p class="option-overview">
57+
<p class="option-overview text-xs">
5658
{{ option.overview }}
5759
</p>
5860
</div>
@@ -61,29 +63,4 @@ async function searchMovies({ search, page, hasNextPage }) {
6163
</FormKit>
6264
<pre wrap>{{ value }}</pre>
6365
</FormKit>
64-
</template>
65-
66-
<style>
67-
.formkit-option {
68-
display: flex;
69-
align-items: center;
70-
justify-content: space-between;
71-
}
72-
73-
.formkit-option img {
74-
width: 100%;
75-
margin-right: 20px;
76-
}
77-
78-
.option-overview {
79-
font-size: 12px;
80-
}
81-
82-
.image-container {
83-
width: 25%;
84-
}
85-
86-
.text-container {
87-
width: 60%;
88-
}
89-
</style>
66+
</template>

.examples/autocomplete-pro/autocomplete-slot-selection.vue

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ const carBrands = [{ label: 'Audi', value: 'audi', logo: 'https://s3.amazonaws.c
1313
value="audi"
1414
>
1515
<!--SELECTION SLOT-->
16-
<template #selection="{ option, handlers }">
17-
<div class="formkit-selection">
18-
<div class="formkit-option">
16+
<template #selection="{ option, classes }">
17+
<div :class="classes.selection">
18+
<div :class="`${classes.option} flex items-center`">
1919
<img
2020
:src="option.logo"
2121
:alt="option.label + ' logo'"
22+
class="w-10 h-10 p-2"
2223
/>
2324
<span>
2425
{{ option.label }}
@@ -39,12 +40,13 @@ const carBrands = [{ label: 'Audi', value: 'audi', logo: 'https://s3.amazonaws.c
3940
:value="['toyota', 'honda']"
4041
>
4142
<!--SELECTION SLOT-->
42-
<template #selection="{ option }">
43-
<div class="formkit-selection">
44-
<div class="formkit-option">
43+
<template #selection="{ option, classes }">
44+
<div :class="`${classes.selection} !p-0`">
45+
<div :class="`${classes.option} flex items-center`">
4546
<img
4647
:src="option.logo"
4748
:alt="option.label + ' logo'"
49+
class="w-10 h-10 p-2"
4850
/>
4951
<span>
5052
{{ option.label }}
@@ -61,10 +63,4 @@ const carBrands = [{ label: 'Audi', value: 'audi', logo: 'https://s3.amazonaws.c
6163
display: flex;
6264
align-items: center;
6365
}
64-
65-
.formkit-option img {
66-
width: 20px;
67-
height: 20px;
68-
margin-right: 10px;
69-
}
7066
</style>
Lines changed: 2 additions & 202 deletions
Original file line numberDiff line numberDiff line change
@@ -1,165 +1,4 @@
1-
<!-- %partial% -->
21
<script setup>
3-
import { createInput } from '@formkit/vue'
4-
5-
/**
6-
* This is an input "feature" — a function that accepts a node and exposes
7-
* some additional functionality to an input. When using schemas, this can
8-
* take the place of a traditional "script" block in a Vue component. In this
9-
* example, we expose:
10-
*
11-
* - An input handler `search`.
12-
* - An input handler `selections`.
13-
* - Commit middleware to place filtered options into the `matches` prop.
14-
*
15-
* Once written, input features are added via the input declaration.
16-
*/
17-
const searchFeature = (node) => {
18-
// We wait for our node to be fully "created" before we start to add our
19-
// handlers to ensure the core Vue plugin has added its context object:
20-
node.on('created', () => {
21-
// Ensure our matches prop starts as an array.
22-
node.props.matches = []
23-
node.props.selection = ''
24-
// When we actually have an value to set:
25-
const setValue = async (e) => {
26-
if (e && typeof e.preventDefault === 'function') e.preventDefault()
27-
node.input(node.props.selection)
28-
node.props.selection = ''
29-
node.props.searchValue = ''
30-
await new Promise((r) => setTimeout(r, 50)) // "next tick"
31-
if (document.querySelector('input#' + node.props.id)) {
32-
document.querySelector('input#' + node.props.id).focus()
33-
}
34-
}
35-
36-
// Perform a soft selection, this is shown as a highlight in the dropdown
37-
const select = (delta) => {
38-
const available = node.props.matches
39-
let idx = available.indexOf(node.props.selection) + delta
40-
if (idx >= available.length) {
41-
idx = 0
42-
} else if (idx < 0) {
43-
idx = available.length - 1
44-
}
45-
node.props.selection = available[idx]
46-
}
47-
48-
// Add some new "handlers" for our autocomplete. The handlers object is
49-
// just a conventionally good place to put event handlers. Auto complete
50-
// inputs always have to deal with lots of keyboard events, so that logic
51-
// is registered here.
52-
Object.assign(node.context.handlers, {
53-
setValue,
54-
selection: (e) => {
55-
// This handler is called when entering data into the search input.
56-
switch (e.key) {
57-
case 'Enter':
58-
return setValue()
59-
case 'ArrowDown':
60-
e.preventDefault()
61-
return select(1)
62-
case 'ArrowUp':
63-
e.preventDefault()
64-
return select(-1)
65-
}
66-
},
67-
search(e) {
68-
node.props.searchValue = e.target.value
69-
},
70-
hover: (e) => {
71-
node.props.selection = e.target.textContent
72-
},
73-
unhover: (e) => {
74-
if (e.target.textContent === node.props.selection) {
75-
node.props.selection = ''
76-
}
77-
},
78-
})
79-
})
80-
81-
// Perform filtering when the search value changes
82-
node.on('prop:searchValue', ({ payload: value }) => {
83-
const results = node.props.options.filter((option) =>
84-
option.toLowerCase().startsWith(value.toLowerCase())
85-
)
86-
if (!results.length) results.push('No matches')
87-
node.props.matches = results
88-
})
89-
}
90-
91-
/**
92-
* This is our input schema responsible for rendering the inner “input”
93-
* section. In our example, we render an text input which will be used
94-
* to filter search results, and an unordered list that shows all remaining
95-
* matches.
96-
*/
97-
const schema = {
98-
if: '$value',
99-
then: [
100-
{
101-
$el: 'a',
102-
attrs: {
103-
id: '$id',
104-
href: '#',
105-
class: '$classes.value',
106-
onClick: '$handlers.setValue',
107-
},
108-
children: '$value',
109-
},
110-
],
111-
else: [
112-
{
113-
$el: 'input',
114-
bind: '$attrs',
115-
attrs: {
116-
id: '$id',
117-
class: '$classes.input',
118-
onKeydown: '$handlers.selection',
119-
onInput: '$handlers.search',
120-
value: '$searchValue',
121-
},
122-
},
123-
{
124-
$el: 'ul',
125-
if: '$matches.length < $options.length',
126-
attrs: {
127-
class: '$classes.dropdown',
128-
},
129-
children: [
130-
{
131-
$el: 'li',
132-
for: ['match', '$matches'],
133-
attrs: {
134-
'data-selected': {
135-
if: '$selection === $match',
136-
then: 'true',
137-
else: 'false',
138-
},
139-
class: '$classes.dropdownItem',
140-
onClick: '$handlers.setValue',
141-
onMouseenter: '$handlers.hover',
142-
onMouseleave: '$handlers.unhover',
143-
},
144-
children: '$match',
145-
},
146-
],
147-
},
148-
],
149-
}
150-
151-
/**
152-
* Finally we create our actual input declaration by using `createInput` this
153-
* places our schema into a "standard" FormKit schema feature set with slots,
154-
* labels, help, messages etc. The return value of this function is a proper
155-
* input declaration.
156-
*/
157-
const autocomplete = createInput(schema, {
158-
props: ['options', 'matches', 'selection', 'searchValue'],
159-
features: [searchFeature],
160-
})
161-
162-
// The states are a long list, so we'll burry them down here:
1632
const stateList = [
1643
'Alabama',
1654
'Alaska',
@@ -214,54 +53,15 @@ const stateList = [
21453
]
21554
</script>
21655

56+
<!-- %partial% -->
21757
<template>
21858
<FormKit
21959
label="U.S. State"
220-
:type="autocomplete"
60+
type="myAutocomplete"
22161
placeholder="Search for a state"
22262
help="What is your favorite U.S. state?"
22363
value="Virginia"
22464
:options="stateList"
22565
/>
22666
</template>
22767
<!-- %partial% -->
228-
229-
<style>
230-
.formkit-dropdown {
231-
position: absolute;
232-
top: 100%;
233-
left: 0;
234-
min-width: 15em;
235-
background-color: white;
236-
box-shadow: 0 0 0.5em rgba(0 0 0 / 10%);
237-
margin: 0;
238-
padding: 0;
239-
list-style-type: none;
240-
overflow: hidden;
241-
border-radius: 0.25em;
242-
}
243-
.formkit-dropdown-item {
244-
padding: 0.5em;
245-
border-bottom: 1px solid #e4e4e4;
246-
}
247-
.formkit-dropdown-item[data-selected='true'] {
248-
background-color: #cfe8fc;
249-
}
250-
.formkit-value {
251-
align-items: center;
252-
background-color: #f5f5f5;
253-
border-radius: 0.25em;
254-
box-sizing: border-box;
255-
color: black;
256-
display: flex;
257-
justify-content: space-between;
258-
padding: 0.55em 0.5em;
259-
text-decoration: none;
260-
width: 100%;
261-
}
262-
.formkit-value::after {
263-
content: '\00D7';
264-
margin-left: 0.5em;
265-
font-size: 1.1em;
266-
}
267-
</style>

0 commit comments

Comments
 (0)