@wishbone-media/spark 0.45.0 → 0.46.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/formkit.config.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // Note: Consumer apps should wrap the returned config with defaultConfig()
2
- import { createAutoAnimatePlugin } from '@formkit/addons';
2
+ import { createAutoAnimatePlugin } from '@formkit/addons'
3
3
  import {
4
4
  createProPlugin,
5
5
  autocomplete,
@@ -12,9 +12,14 @@ import {
12
12
  taglist,
13
13
  toggle,
14
14
  togglebuttons,
15
- } from '@formkit/pro';
16
- import { rootClasses } from '@wishbone-media/spark/formkit.theme.mjs';
17
- import { formKitIcons, formKitIconLoader, formKitGenesisOverride } from '@wishbone-media/spark';
15
+ } from '@formkit/pro'
16
+ import { rootClasses } from '@wishbone-media/spark/formkit.theme.mjs'
17
+ import {
18
+ formKitIcons,
19
+ formKitIconLoader,
20
+ formKitGenesisOverride,
21
+ createPasswordTogglePlugin,
22
+ } from '@wishbone-media/spark'
18
23
 
19
24
  const autoAnimatePlugin = createAutoAnimatePlugin(
20
25
  {
@@ -22,20 +27,22 @@ const autoAnimatePlugin = createAutoAnimatePlugin(
22
27
  // default:
23
28
  duration: 250,
24
29
  easing: 'ease-in-out',
25
- delay: 0
30
+ delay: 0,
26
31
  },
27
32
  {
28
33
  /* optional animation targets object */
29
34
  // default:
30
35
  global: ['outer', 'inner'],
31
36
  form: ['form'],
32
- repeater: ['items']
33
- }
34
- );
37
+ repeater: ['items'],
38
+ },
39
+ )
35
40
 
36
41
  export default function createFormKitConfig(formKitProKey) {
37
42
  if (!formKitProKey) {
38
- throw new Error('FormKit Pro key is required. Please provide VITE_FORMKIT_PRO_KEY in your environment variables.');
43
+ throw new Error(
44
+ 'FormKit Pro key is required. Please provide VITE_FORMKIT_PRO_KEY in your environment variables.',
45
+ )
39
46
  }
40
47
 
41
48
  const proPlugin = createProPlugin(formKitProKey, {
@@ -49,18 +56,18 @@ export default function createFormKitConfig(formKitProKey) {
49
56
  taglist,
50
57
  toggle,
51
58
  togglebuttons,
52
- });
59
+ })
53
60
 
54
61
  // Return plain config object - consumer apps wrap with defaultConfig()
55
62
  return {
56
63
  config: {
57
- rootClasses
64
+ rootClasses,
58
65
  },
59
66
  icons: {
60
67
  ...formKitGenesisOverride, // FontAwesome replacements for FormKit's built-in icons
61
- ...formKitIcons, // Additional FA icons available via prefix-icon/suffix-icon
68
+ ...formKitIcons, // Additional FA icons available via prefix-icon/suffix-icon
62
69
  },
63
70
  iconLoader: formKitIconLoader,
64
- plugins: [proPlugin, autoAnimatePlugin]
65
- };
71
+ plugins: [proPlugin, autoAnimatePlugin, createPasswordTogglePlugin()],
72
+ }
66
73
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wishbone-media/spark",
3
- "version": "0.45.0",
3
+ "version": "0.46.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -40,6 +40,8 @@ import {
40
40
  faXmark,
41
41
  faSignOut,
42
42
  faEye,
43
+ faEyeSlash,
44
+ faLock,
43
45
  faUndo,
44
46
  faBolt,
45
47
  faCloudDownload,
@@ -109,6 +111,8 @@ export const Icons = {
109
111
  farXmark: faXmark,
110
112
  farSignOut: faSignOut,
111
113
  farEye: faEye,
114
+ farEyeSlash: faEyeSlash,
115
+ farLock: faLock,
112
116
  farUndo: faUndo,
113
117
  farBolt: faBolt,
114
118
  farCloudDownload: faCloudDownload,
@@ -0,0 +1,56 @@
1
+ function isTruthy(value) {
2
+ return value !== undefined && value !== false
3
+ }
4
+
5
+ function loadIcon(node, sectionKey, iconName) {
6
+ const iconHandler = node.props.iconHandler
7
+ if (!iconHandler) return
8
+
9
+ const rawProp = `_raw${sectionKey.charAt(0).toUpperCase()}${sectionKey.slice(1)}`
10
+ node.addProps([sectionKey, rawProp])
11
+
12
+ node.props[sectionKey] = iconName
13
+ const svg = iconHandler(iconName)
14
+ if (svg instanceof Promise) {
15
+ svg.then((s) => {
16
+ node.props[rawProp] = s
17
+ })
18
+ } else {
19
+ node.props[rawProp] = svg
20
+ }
21
+
22
+ node.on(`prop:${sectionKey}`, (event) => {
23
+ const newSvg = iconHandler(event.payload)
24
+ if (newSvg instanceof Promise) {
25
+ newSvg.then((s) => {
26
+ node.props[rawProp] = s
27
+ })
28
+ } else {
29
+ node.props[rawProp] = newSvg
30
+ }
31
+ })
32
+ }
33
+
34
+ export function createPasswordTogglePlugin() {
35
+ return function passwordTogglePlugin(node) {
36
+ if (node.props.type !== 'password') return
37
+
38
+ node.addProps(['toggleVisibility', 'showPrefixLock'])
39
+
40
+ if (isTruthy(node.props.toggleVisibility)) {
41
+ loadIcon(node, 'suffixIcon', 'farEyeSlash')
42
+ node.addProps(['onSuffixIconClick'])
43
+ node.props.onSuffixIconClick = (innerNode) => {
44
+ const el = document.getElementById(innerNode.props.id)
45
+ if (!el) return
46
+ const isHidden = el.type === 'password'
47
+ el.type = isHidden ? 'text' : 'password'
48
+ innerNode.props.suffixIcon = isHidden ? 'farEye' : 'farEyeSlash'
49
+ }
50
+ }
51
+
52
+ if (isTruthy(node.props.showPrefixLock)) {
53
+ loadIcon(node, 'prefixIcon', 'farLock')
54
+ }
55
+ }
56
+ }
@@ -17,3 +17,4 @@ export {
17
17
  export { createAxiosInstance, setupAxios, getAxiosInstance } from './axios.js'
18
18
  export { createBootstrapService } from './app-bootstrap.js'
19
19
  export { setupTooltip } from './tooltip.js'
20
+ export { createPasswordTogglePlugin } from './formkit-password.js'