diff --git a/packages/docs/nuxt.config.ts b/packages/docs/nuxt.config.ts index 25ee9bbd23..020a10c2f2 100644 --- a/packages/docs/nuxt.config.ts +++ b/packages/docs/nuxt.config.ts @@ -74,12 +74,14 @@ export default defineNuxtConfig({ nitro: { // compressPublicAssets: true, }, + gtm: { id: process.env.GTM_ID, // Your GTM single container ID, array of container ids ['GTM-xxxxxx', 'GTM-yyyyyy'] or array of objects [{id: 'GTM-xxxxxx', queryParams: { gtm_auth: 'abc123', gtm_preview: 'env-4', gtm_cookies_win: 'x'}}, {id: 'GTM-yyyyyy', queryParams: {gtm_auth: 'abc234', gtm_preview: 'env-5', gtm_cookies_win: 'x'}}], // Your GTM single container ID or array of container ids ['GTM-xxxxxx', 'GTM-yyyyyy'] enabled: process.env.GTM_ENABLED === 'true', // defaults to true. Plugin can be disabled by setting this to false for Ex: enabled: !!GDPR_Cookie (optional) }, modules: [ + '@formkit/nuxt', './modules/repl', './modules/banner', './modules/vuestic', @@ -139,7 +141,6 @@ export default defineNuxtConfig({ }, }, - css: [ '@/assets/css/tailwind.css', ], @@ -175,4 +176,10 @@ export default defineNuxtConfig({ } } }, + + formkit: { + autoImport: true, + }, + + compatibilityDate: '2024-11-29', }); diff --git a/packages/docs/package.json b/packages/docs/package.json index 7bb6444d14..6272da8bb5 100644 --- a/packages/docs/package.json +++ b/packages/docs/package.json @@ -41,6 +41,8 @@ }, "dependencies": { "@docsearch/js": "^3.2.1", + "@formkit/nuxt": "^1.6.9", + "@formkit/vue": "^1.6.9", "@funken-studio/sitemap-nuxt-3": "^4.0.4", "@nuxtjs/google-fonts": "^3.0.1", "@types/acorn": "^6.0.0", diff --git a/packages/docs/page-config/extensions/formkit/examples/BasicForm.vue b/packages/docs/page-config/extensions/formkit/examples/BasicForm.vue new file mode 100644 index 0000000000..bcc0ad3498 --- /dev/null +++ b/packages/docs/page-config/extensions/formkit/examples/BasicForm.vue @@ -0,0 +1,65 @@ + + + + + diff --git a/packages/docs/page-config/extensions/formkit/examples/Checkbox.vue b/packages/docs/page-config/extensions/formkit/examples/Checkbox.vue new file mode 100644 index 0000000000..50956a6b8e --- /dev/null +++ b/packages/docs/page-config/extensions/formkit/examples/Checkbox.vue @@ -0,0 +1,15 @@ + + + diff --git a/packages/docs/page-config/extensions/formkit/examples/MultiStepForm.vue b/packages/docs/page-config/extensions/formkit/examples/MultiStepForm.vue new file mode 100644 index 0000000000..93b965eb6e --- /dev/null +++ b/packages/docs/page-config/extensions/formkit/examples/MultiStepForm.vue @@ -0,0 +1,238 @@ + + + + + diff --git a/packages/docs/page-config/extensions/formkit/examples/useSteps.js b/packages/docs/page-config/extensions/formkit/examples/useSteps.js new file mode 100644 index 0000000000..2be132b500 --- /dev/null +++ b/packages/docs/page-config/extensions/formkit/examples/useSteps.js @@ -0,0 +1,69 @@ +import { reactive, toRef, ref, watch } from 'vue' +import { getNode, createMessage } from '@formkit/core' + +export default function useSteps () { + const activeStep = ref('') + const steps = reactive({}) + const visitedSteps = ref([]) // track visited steps + + // NEW: watch our activeStep and store visited steps + // to know when to show errors + watch(activeStep, (newStep, oldStep) => { + if (oldStep && !visitedSteps.value.includes(oldStep)) { + visitedSteps.value.push(oldStep) + } + // NEW: trigger showing validation on fields + // within all visited steps + visitedSteps.value.forEach((step) => { + const node = getNode(step) + node.walk((n) => { + n.store.set( + createMessage({ + key: 'submitted', + value: true, + visible: false, + }) + ) + }) + }) + }) + + const setStep = (delta) => { + const stepNames = Object.keys(steps) + const currentIndex = stepNames.indexOf(activeStep.value) + activeStep.value = stepNames[currentIndex + delta] + } + + const stepPlugin = (node) => { + if (node.props.type === "group") { + // builds an object of the top-level groups + steps[node.name] = steps[node.name] || {} + + node.on('created', () => { + // use 'on created' to ensure context object is available + steps[node.name].valid = toRef(node.context.state, 'valid') + }) + + // listen for changes in error count and store it + node.on('count:errors', ({ payload: count }) => { + steps[node.name].errorCount = count + }) + + // listen for changes in count of blocking validations messages + node.on('count:blocking', ({ payload: count }) => { + steps[node.name].blockingCount = count + }) + + // set the active tab to the 1st tab + if (activeStep.value === '') { + activeStep.value = node.name + } + + // Stop plugin inheritance to descendant nodes + return false + } + } + + // NEW: include visitedSteps in our return + return { activeStep, visitedSteps, steps, stepPlugin, setStep } +} diff --git a/packages/docs/page-config/extensions/formkit/examples/utils.js b/packages/docs/page-config/extensions/formkit/examples/utils.js new file mode 100644 index 0000000000..b4754cfa3b --- /dev/null +++ b/packages/docs/page-config/extensions/formkit/examples/utils.js @@ -0,0 +1,32 @@ +export { axios, camel2title } + +// This is just a mock of an actual axios instance. +const axios = { + post: (formData) => { + return new Promise((resolve, reject) => { + let response = { status: 200 } + if (formData.organizationInfo.org_name.toLowerCase().trim() !== 'formkit') { + response = { + status: 400, + formErrors: ['There was an error in this form, please correct and re-submit to validate.'], + fieldErrors: { + 'organizationInfo.org_name': 'Organization Name must be "FormKit", we tricked you!' + } + } + } + setTimeout(() => { + if (response.status === 200) { + resolve(response) + } else { + reject(response) + } + }, 1500) + }) + + } +} + +const camel2title = (str) => str + .replace(/([A-Z])/g, (match) => ` ${match}`) + .replace(/^./, (match) => match.toUpperCase()) + .trim() diff --git a/packages/docs/page-config/extensions/formkit/index.ts b/packages/docs/page-config/extensions/formkit/index.ts new file mode 100644 index 0000000000..50fcf258ad --- /dev/null +++ b/packages/docs/page-config/extensions/formkit/index.ts @@ -0,0 +1,44 @@ +const installCommandObject = { + npm: "npm install @vuestic/formkit", + yarn: "yarn add @vuestic/formkit", +}; + + +const setupCode = ` +// main.* +import { createApp } from 'vue' +import App from './App.vue' + +import { plugin, defaultConfig } from '@formkit/vue' + +createApp(App).use(plugin, defaultConfig).use(createVuestic()).mount('#app') +`; + +const dependencies = { + "@vuestic/formkit": "latest", +}; + +export default definePageConfig({ + blocks: [ + block.title("FormKit integration"), + block.paragraph("If you need a powerful tool for building forms, we recommend using the [FormKit](https://formkit.com/getting-started/what-is-formkit)[[target=_blank]]. Vuestic UI provides a ready-made style theme for this framework."), + block.headline("FormKit installation"), + block.paragraph("To start using FormKit, install the dependencies in your project."), + block.code(installCommandObject, "bash"), + block.paragraph("Then add the plugin to your main.* file"), + block.code(setupCode, "js"), + block.alert("Vuestic-UI provides styles for FormKit components and doesn't change any functionality. For more examples visit the official [FormKit documentation page](https://formkit.com/guides/build-a-multi-step-form)[[target=_blank]].", "warning"), + block.example("Checkbox", { + codesandboxConfig: { dependencies }, + title: "Checkbox", + }), + block.example("BasicForm", { + codesandboxConfig: { dependencies }, + title: "Basic Form", + }), + block.example("MultiStepForm", { + codesandboxConfig: { dependencies }, + title: "Multi Step Form", + }), + ], +}); diff --git a/packages/docs/page-config/navigationRoutes.ts b/packages/docs/page-config/navigationRoutes.ts index aa80c26980..4a3460b981 100644 --- a/packages/docs/page-config/navigationRoutes.ts +++ b/packages/docs/page-config/navigationRoutes.ts @@ -651,6 +651,10 @@ export const navigationRoutes: NavigationRoute[] = [ meta: { badge: navigationBadge.new('1.9.9'), } + }, + { + name: 'formkit', + displayName: 'FormKit integration', } ], }, diff --git a/packages/formkit/package.json b/packages/formkit/package.json index 5e86b830eb..552ec2cec6 100644 --- a/packages/formkit/package.json +++ b/packages/formkit/package.json @@ -1,7 +1,8 @@ { "name": "@vuestic/formkit", "version": "0.0.1", - "main": "dist/index.js", + "main": "src/index.ts", + "types": "src/index.ts", "license": "MIT", "dependencies": { "@formkit/core": "^1.6.7", diff --git a/packages/formkit/playground/src/App.vue b/packages/formkit/playground/src/App.vue index 338fac448b..cb69581423 100644 --- a/packages/formkit/playground/src/App.vue +++ b/packages/formkit/playground/src/App.vue @@ -1,9 +1,9 @@