Skip to content

Commit d4023e3

Browse files
committed
feat: add PrimeLabel component with help text support for FormKit nodes showing custom plugin sample for demo
1 parent a44d2a2 commit d4023e3

File tree

4 files changed

+63
-3
lines changed

4 files changed

+63
-3
lines changed

dev/components.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ declare module 'vue' {
1212
AppTopbar: typeof import('./components/app/AppTopbar.vue')['default']
1313
PrimeData: typeof import('./components/demo/PrimeData.vue')['default']
1414
PrimeInput: typeof import('./components/demo/PrimeInput.vue')['default']
15+
PrimeLabel: typeof import('./components/demo/PrimeLabel.vue')['default']
1516
PrimeOutput: typeof import('./components/demo/PrimeOutput.vue')['default']
1617
PrimeSchemaEditor: typeof import('./components/demo/PrimeSchemaEditor.vue')['default']
1718
RouterLink: typeof import('vue-router')['RouterLink']

dev/components/demo/PrimeLabel.vue

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<script setup lang="ts">
2+
defineProps({
3+
label: {
4+
type: String,
5+
},
6+
help: {
7+
type: String,
8+
},
9+
required: {
10+
type: Boolean,
11+
default: false,
12+
},
13+
requiredSymbol: {
14+
type: String,
15+
default: '*',
16+
},
17+
})
18+
</script>
19+
20+
<template>
21+
<span v-if="help" v-tooltip="help" class="p-formkit-label">{{ label }}</span>
22+
<span v-else class="p-formkit-label">{{ label }}</span>
23+
<span class="p-formkit-required">{{ requiredSymbol }}</span>
24+
</template>
25+
26+
<style scoped lang="scss">
27+
28+
</style>

dev/modules/formkit.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,40 @@
1+
import type { FormKitExtendableSchemaRoot, FormKitNode } from '@formkit/core'
12
import type { UserModule } from '@/types'
23
import { createAutoAnimatePlugin, createMultiStepPlugin } from '@formkit/addons'
3-
import { de, en } from '@formkit/i18n'
44

5+
import { de, en } from '@formkit/i18n'
56
import { defaultConfig, plugin } from '@formkit/vue'
67
import { primeInputs, primeOutputs } from 'my-library/definitions'
7-
import { addPrimeAsteriskPlugin } from 'my-library/plugins'
88
import '@formkit/addons/css/multistep'
99

10+
export function addPrimeLabelPlugin(node: FormKitNode): void {
11+
if (!node.props.type.startsWith('prime'))
12+
return
13+
14+
node.on('created', () => {
15+
if (node.props.definition?.schema) {
16+
const schemaFn = node.props.definition?.schema as FormKitExtendableSchemaRoot
17+
node.props.definition!.schema = (sectionsSchema = {}) => {
18+
sectionsSchema.label = {
19+
children: [
20+
{
21+
$cmp: 'PrimeLabel',
22+
props: {
23+
label: '$label',
24+
help: '$help',
25+
},
26+
},
27+
],
28+
}
29+
sectionsSchema.help = {
30+
}
31+
32+
return schemaFn(sectionsSchema)
33+
}
34+
}
35+
})
36+
}
37+
1038
export const install: UserModule = ({ app }) => {
1139
app.use(plugin, defaultConfig({
1240
locales: { de, en },
@@ -29,7 +57,7 @@ export const install: UserModule = ({ app }) => {
2957
repeater: ['items'],
3058
},
3159
),
32-
addPrimeAsteriskPlugin,
60+
addPrimeLabelPlugin,
3361
createMultiStepPlugin(),
3462
],
3563
}))

dev/modules/primevue.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import Toast from 'primevue/toast'
2020
import ToastService from 'primevue/toastservice'
2121
import Toolbar from 'primevue/toolbar'
2222
import Tooltip from 'primevue/tooltip'
23+
import PrimeLabel from '../components/demo/PrimeLabel.vue'
2324
import 'primeicons/primeicons.css'
2425

2526
export const install: UserModule = ({ app }) => {
@@ -41,6 +42,8 @@ export const install: UserModule = ({ app }) => {
4142
app.component('Toast', Toast)
4243
app.component('Toolbar', Toolbar)
4344

45+
app.component('PrimeLabel', PrimeLabel)
46+
4447
app.use(PrimeVue, {
4548
theme: {
4649
preset: Aura,

0 commit comments

Comments
 (0)