Skip to content

Commit

Permalink
feat(primevue-nuxt): use official primevue nuxt module
Browse files Browse the repository at this point in the history
  • Loading branch information
sfxcode committed Nov 2, 2023
1 parent c116fdc commit d61b874
Show file tree
Hide file tree
Showing 7 changed files with 1,340 additions and 1,219 deletions.
16 changes: 16 additions & 0 deletions composables/usePrimeDataTable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { ref } from 'vue'

export function usePrimeDataTable () {
const tableData = ref([])

const filters = ref({})
const dataTableRef = ref()

function exportCSV () {
dataTableRef.value?.exportCSV()
}

return {
tableData, filters, dataTableRef, exportCSV
}
}
12 changes: 3 additions & 9 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export default defineNuxtConfig({
}
},
modules: [
'nuxt-primevue',
'@formkit/nuxt',
'@sfxcode/nuxt-primevue',
'@unocss/nuxt',
'@pinia/nuxt',
'@nuxtjs/i18n',
Expand All @@ -39,21 +39,15 @@ export default defineNuxtConfig({

},
primevue: {
config: {
ripple: true
components: {
exclude: ['Chart']
}
},
css: [
'primevue/resources/primevue.css',
'primeicons/primeicons.css',
'@sfxcode/formkit-primevue/dist/sass/formkit-primevue.scss'
],
pinia: {
autoImports: [
// automatically imports `defineStore`
'defineStore' // import { defineStore } from 'pinia'
]
},
build: {
transpile: ['nuxt', 'primevue', 'formkit-primevue']
},
Expand Down
24 changes: 13 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,34 @@
"test:coverage": "vitest run --coverage"
},
"devDependencies": {
"@formkit/nuxt": "1.2.2",
"@iconify-json/carbon": "^1.1.21",
"@iconify-json/mdi": "^1.1.54",
"@iconify-json/mdi": "^1.1.55",
"@iconify-json/prime": "^1.1.6",
"@iconify-json/twemoji": "^1.1.12",
"@nuxt/content": "2.8.5",
"@nuxt/devtools": "1.0.0-beta.2",
"@nuxt/test-utils": "^3.7.4",
"@nuxt/content": "2.9.0",
"@nuxt/devtools": "1.0.0",
"@nuxt/test-utils": "^3.8.0",
"@nuxtjs/eslint-config-typescript": "12.1.0",
"@nuxtjs/i18n": "8.0.0-rc.5",
"@pinia/nuxt": "^0.5.0",
"@sfxcode/nuxt-primevue": "^1.4.1",
"@pinia/nuxt": "^0.5.1",
"@sfxcode/formkit-primevue": "^1.4.5",
"@tiptap/extension-highlight": "^2.1.12",
"@tiptap/extension-text-align": "^2.1.12",
"@tiptap/extension-text-style": "^2.1.12",
"@tiptap/pm": "^2.1.12",
"@tiptap/starter-kit": "^2.1.12",
"@tiptap/vue-3": "^2.1.12",
"@unocss/nuxt": "0.56.5",
"@unocss/nuxt": "0.57.1",
"@vitejs/plugin-vue": "^4.4.0",
"@vitest/ui": "^0.34.6",
"@vueuse/nuxt": "^10.5.0",
"jsdom": "^22.1.0",
"c8": "^8.0.1",
"eslint": "^8.51.0",
"nuxt": "3.7.4",
"sass": "^1.69.3",
"eslint": "^8.52.0",
"jsdom": "^22.1.0",
"nuxt": "3.8.0",
"nuxt-primevue": "^0.1.0",
"sass": "^1.69.5",
"typescript": "^5.2.2",
"unstorage": "^1.9.0",
"vitest": "^0.34.6"
Expand Down
1 change: 0 additions & 1 deletion pages/prime/datatable.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script setup lang='ts'>
import { FilterMatchMode } from 'primevue/api'
import { usePrimeDataTable } from '#imports'
const { tableData, filters, dataTableRef, exportCSV } = usePrimeDataTable()
Expand Down
43 changes: 42 additions & 1 deletion pages/prime/messages.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,47 @@
<script setup lang="ts">
import { useToast } from 'primevue/usetoast'
import type { ToastMessageOptions } from 'primevue/toast'
const toast = useToast()
const showMessage = (severity: ToastMessageOptions['severity'], summary: string, detail: string) => {
toast.add({ severity, summary, detail, life: 3000 })
}
</script>

<template>
<div class="card">
<PrimeDemoToast />
<div class="card">
<h2>PrimeVue Toast Demo</h2>

<div class="grid grid-cols-4">
<div>
<Button label="Success" class="p-button-success" @click="showMessage('success', 'Success Message', 'Message Content')" />
</div>
<div>
<Button label="Info" class="p-button-info" @click="showMessage('info', 'Info Message', 'Message Content')" />
</div>
<div>
<Button label="Warn" class="p-button-warning" @click="showMessage('warn', 'Warn Message', 'Message Content')" />
</div>
<div>
<Button label="Error" class="p-button-danger" @click="showMessage('error', 'Error Message', 'Message Content')" />
</div>
<Toast />
</div>
<h2>Messages</h2>
<Message severity="success">
Success Message Content
</Message>
<Message severity="info">
Info Message Content
</Message>
<Message severity="warn">
Warning Message Content
</Message>
<Message severity="error">
Error Message Content
</Message>
</div>
</div>
</template>

Expand Down
138 changes: 131 additions & 7 deletions pages/prime/validation.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,137 @@
<script setup lang='ts'>
import { FormKitSchema } from '@formkit/vue'
import { ref, reactive } from 'vue'
const options = [
{ label: 'Every page load', value: 'refresh' },
{ label: 'Ever hour', value: 'hourly' },
{ label: 'Every day', value: 'daily' }
]
const schema = reactive(
[
{
$el: 'h2',
children: ['Validation with FormKit']
},
{
$el: 'h3',
children: ['Inputs from PrimeVue']
},
{
$formkit: 'primeInputText',
name: 'email',
label: 'Email',
help: 'This will be used for your account.',
validation: 'required|email'
},
{
$formkit: 'primeTextarea',
name: 'myText',
label: 'Text',
rows: '5'
},
{
$formkit: 'primeCalendar',
name: 'myCalendar',
label: 'Calendar',
validation: '',
showIcon: true
},
{
$formkit: 'primeInputText',
name: 'password',
label: 'Password',
help: 'Enter your new password.',
validation: 'required|length:5,16'
},
{
$formkit: 'primePassword',
name: 'password_confirm',
label: 'Confirm password',
toggleMask: true,
feedback: false,
help: 'Enter your new password again to confirm it.',
validation: 'required|confirm',
validationLabel: 'password confirmation'
},
{
$formkit: 'primeCheckbox',
name: 'eu_citizen',
id: 'eu',
label: 'Are you a european citizen?'
},
{
$formkit: 'primeDropdown',
if: '$eu_citizen', // 👀 Oooo, conditionals!
name: 'cookie_notice',
label: 'Cookie notice frequency',
value: 'hourly',
showClear: false,
filter: false,
options,
help: 'How often should we display a cookie notice?',
class: 'test'
},
{
$formkit: 'primeSlider',
name: 'slider',
label: 'Max messages',
style: 'width: 200px;margin-top: 6px;margin-bottom: 4px',
min: 5,
step: 5,
value: 10
},
{
$formkit: 'primeChips',
name: 'chips',
label: 'Use Chips'
},
{
$formkit: 'primeKnob',
name: 'knob',
label: 'Use Knob',
value: 50
}
]
)
const data = ref({})
const submitHandler = async () => {
// Lets pretend this is an ajax request:
await new Promise(resolve => setTimeout(resolve, 1000))
}
</script>
<template>
<div>
<div class="card">
<div class="max-w-xl">
<PrimeDemoForm />
<div class="card flex flex-wrap gap-12">
<div class="basis-1/2 md:basis-1/3">
<span class="" />
<div class="myFormkit">
<FormKit
id="form"
v-model="data"
type="form"
:submit-attrs="{
inputClass: 'p-button p-component',
wrapperClass: '',
outerClass: ''
}"
@submit="submitHandler"
>
<FormKitSchema :schema="schema" :data="data" />
</FormKit>
</div>
</div>
<div class="basis-1/2 md:basis-1/3">
<h2>Formkit Debug</h2>
<h3>Data</h3>
<pre>{{ data }}</pre>
</div>
</div>
</template>

<script setup lang='ts'>
</script>
<style scoped></style>
Loading

0 comments on commit d61b874

Please sign in to comment.