@witchcraft/ui 0.0.1 → 0.1.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.
Files changed (155) hide show
  1. package/README.md +18 -28
  2. package/dist/module.d.mts +3 -1
  3. package/dist/module.d.ts +3 -1
  4. package/dist/module.json +2 -2
  5. package/dist/module.mjs +20 -11
  6. package/dist/runtime/assets/base.css +1 -1
  7. package/dist/runtime/assets/locales/en.json +2 -2
  8. package/dist/runtime/assets/tailwind.css +1 -1
  9. package/dist/runtime/assets/utils.css +1 -0
  10. package/dist/runtime/build/WitchcraftUiResolver.js +1 -1
  11. package/dist/runtime/components/Icon/Icon.vue +10 -5
  12. package/dist/runtime/components/LibButton/LibButton.vue +41 -46
  13. package/dist/runtime/components/LibCheckbox/LibCheckbox.vue +7 -3
  14. package/dist/runtime/components/LibColorInput/LibColorInput.vue +111 -36
  15. package/dist/runtime/components/LibColorPicker/LibColorPicker.stories.d.ts +2 -0
  16. package/dist/runtime/components/LibColorPicker/LibColorPicker.stories.js +26 -9
  17. package/dist/runtime/components/LibColorPicker/LibColorPicker.vue +242 -131
  18. package/dist/runtime/components/LibColorPicker/utils/safeConvertToHsva.d.ts +2 -0
  19. package/dist/runtime/components/LibColorPicker/utils/safeConvertToHsva.js +18 -0
  20. package/dist/runtime/components/LibColorPicker/utils/safeConvertToRgba.d.ts +2 -0
  21. package/dist/runtime/components/LibColorPicker/utils/safeConvertToRgba.js +17 -0
  22. package/dist/runtime/components/LibColorPicker/utils/toLowPrecisionRgbaString.d.ts +2 -0
  23. package/dist/runtime/components/LibColorPicker/utils/toLowPrecisionRgbaString.js +8 -0
  24. package/dist/runtime/components/LibColorPicker/utils/truncate.d.ts +1 -0
  25. package/dist/runtime/components/LibColorPicker/utils/truncate.js +5 -0
  26. package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.stories.js +1 -1
  27. package/dist/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue +11 -8
  28. package/dist/runtime/components/LibDatePicker/LibDatePicker.vue +4 -17
  29. package/dist/runtime/components/LibDatePicker/LibRangeDatePicker.vue +192 -131
  30. package/dist/runtime/components/LibDatePicker/LibSingleDatePicker.vue +183 -115
  31. package/dist/runtime/components/LibDatePicker/LibTimeZonePicker.vue +3 -3
  32. package/dist/runtime/components/LibDebug/LibDebug.vue +15 -5
  33. package/dist/runtime/components/LibDevOnly/LibDevOnly.vue +1 -3
  34. package/dist/runtime/components/LibFileInput/LibFileInput.vue +54 -28
  35. package/dist/runtime/components/{LibInput/LibInput.stories.d.ts → LibInputDeprecated/LibInputDeprecated.stories.d.ts} +6 -6
  36. package/dist/runtime/components/{LibInput/LibInput.stories.js → LibInputDeprecated/LibInputDeprecated.stories.js} +64 -19
  37. package/{src/runtime/components/LibInput/LibInput.vue → dist/runtime/components/LibInputDeprecated/LibInputDeprecated.vue} +40 -33
  38. package/dist/runtime/components/LibLabel/LibLabel.vue +2 -2
  39. package/dist/runtime/components/LibMultiValues/LibMultiValues.stories.d.ts +1 -1
  40. package/dist/runtime/components/LibMultiValues/LibMultiValues.stories.js +5 -4
  41. package/dist/runtime/components/LibMultiValues/LibMultiValues.vue +11 -12
  42. package/dist/runtime/components/LibNotifications/LibNotification.vue +19 -10
  43. package/dist/runtime/components/LibNotifications/LibNotifications.stories.js +2 -2
  44. package/dist/runtime/components/LibNotifications/LibNotifications.vue +20 -11
  45. package/dist/runtime/components/LibPagination/LibPagination.stories.js +2 -2
  46. package/dist/runtime/components/LibPagination/LibPagination.vue +19 -19
  47. package/dist/runtime/components/LibPalette/LibPalette.vue +3 -3
  48. package/dist/runtime/components/LibPopup/LibPopup.stories.js +2 -2
  49. package/dist/runtime/components/LibPopup/LibPopup.vue +30 -66
  50. package/dist/runtime/components/LibProgressBar/LibProgressBar.vue +3 -1
  51. package/dist/runtime/components/LibRecorder/LibRecorder.vue +2 -2
  52. package/dist/runtime/components/LibRoot/LibRoot.vue +14 -1
  53. package/dist/runtime/components/LibSimpleInput/LibSimpleInput.stories.js +1 -1
  54. package/dist/runtime/components/LibSimpleInput/LibSimpleInput.vue +5 -7
  55. package/dist/runtime/components/LibSuggestions/LibSuggestions.vue +42 -25
  56. package/dist/runtime/components/LibTable/LibTable.vue +8 -8
  57. package/dist/runtime/components/Scrolling.stories.d.ts +6 -0
  58. package/dist/runtime/components/Scrolling.stories.js +44 -0
  59. package/dist/runtime/components/Template/NAME.vue +1 -1
  60. package/dist/runtime/components/TestControls/TestControls.vue +1 -1
  61. package/dist/runtime/components/index.d.ts +12 -11
  62. package/dist/runtime/components/index.js +12 -11
  63. package/dist/runtime/components/shared/props.d.ts +81 -16
  64. package/dist/runtime/components/shared/storyHelpers/playInput.js +5 -5
  65. package/dist/runtime/components/shared/storyHelpers/playSuggestions.js +15 -11
  66. package/dist/runtime/composables/index.d.ts +5 -0
  67. package/dist/runtime/composables/index.js +5 -0
  68. package/dist/runtime/composables/useDivideAttrs.js +1 -0
  69. package/dist/runtime/composables/useDragWithThreshold.d.ts +71 -0
  70. package/dist/runtime/composables/useDragWithThreshold.js +40 -0
  71. package/dist/runtime/composables/usePreHydrationValue.d.ts +12 -0
  72. package/dist/runtime/composables/usePreHydrationValue.js +15 -0
  73. package/dist/runtime/composables/useSetupI18n.d.ts +2 -0
  74. package/dist/runtime/composables/useSetupI18n.js +5 -1
  75. package/dist/runtime/composables/useSuggestions.d.ts +7 -5
  76. package/dist/runtime/composables/useSuggestions.js +94 -57
  77. package/dist/runtime/directives/vResizableCols.js +3 -1
  78. package/dist/runtime/helpers/NotificationHandler.d.ts +5 -0
  79. package/dist/runtime/helpers/index.d.ts +3 -1
  80. package/dist/runtime/helpers/index.js +3 -1
  81. package/dist/runtime/types/index.d.ts +6 -0
  82. package/dist/runtime/utils/notifyIfError.d.ts +14 -0
  83. package/dist/runtime/utils/notifyIfError.js +29 -0
  84. package/package.json +18 -20
  85. package/src/module.ts +31 -12
  86. package/src/runtime/assets/base.css +10 -1
  87. package/src/runtime/assets/locales/en.json +2 -2
  88. package/src/runtime/assets/tailwind.css +1 -1
  89. package/src/runtime/assets/{style.css → utils.css} +86 -4
  90. package/src/runtime/build/WitchcraftUiResolver.ts +1 -1
  91. package/src/runtime/components/Icon/Icon.vue +10 -5
  92. package/src/runtime/components/LibButton/LibButton.vue +41 -46
  93. package/src/runtime/components/LibCheckbox/LibCheckbox.vue +7 -3
  94. package/src/runtime/components/LibColorInput/LibColorInput.vue +111 -36
  95. package/src/runtime/components/LibColorPicker/LibColorPicker.stories.ts +25 -4
  96. package/src/runtime/components/LibColorPicker/LibColorPicker.vue +242 -131
  97. package/src/runtime/components/LibColorPicker/utils/safeConvertToHsva.ts +25 -0
  98. package/src/runtime/components/LibColorPicker/utils/safeConvertToRgba.ts +23 -0
  99. package/src/runtime/components/LibColorPicker/utils/toLowPrecisionRgbaString.ts +13 -0
  100. package/src/runtime/components/LibColorPicker/utils/truncate.ts +6 -0
  101. package/src/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.stories.ts +1 -1
  102. package/src/runtime/components/LibDarkModeSwitcher/LibDarkModeSwitcher.vue +11 -8
  103. package/src/runtime/components/LibDatePicker/LibDatePicker.vue +4 -17
  104. package/src/runtime/components/LibDatePicker/LibRangeDatePicker.vue +192 -131
  105. package/src/runtime/components/LibDatePicker/LibSingleDatePicker.vue +183 -115
  106. package/src/runtime/components/LibDatePicker/LibTimeZonePicker.vue +3 -3
  107. package/src/runtime/components/LibDebug/LibDebug.vue +15 -5
  108. package/src/runtime/components/LibDevOnly/LibDevOnly.vue +1 -3
  109. package/src/runtime/components/LibFileInput/LibFileInput.vue +54 -28
  110. package/src/runtime/components/{LibInput/LibInput.stories.ts → LibInputDeprecated/LibInputDeprecated.stories.ts} +64 -19
  111. package/{dist/runtime/components/LibInput/LibInput.vue → src/runtime/components/LibInputDeprecated/LibInputDeprecated.vue} +40 -33
  112. package/src/runtime/components/LibLabel/LibLabel.vue +2 -2
  113. package/src/runtime/components/LibMultiValues/LibMultiValues.stories.ts +5 -4
  114. package/src/runtime/components/LibMultiValues/LibMultiValues.vue +11 -12
  115. package/src/runtime/components/LibNotifications/LibNotification.vue +19 -10
  116. package/src/runtime/components/LibNotifications/LibNotifications.stories.ts +2 -2
  117. package/src/runtime/components/LibNotifications/LibNotifications.vue +20 -11
  118. package/src/runtime/components/LibPagination/LibPagination.stories.ts +2 -2
  119. package/src/runtime/components/LibPagination/LibPagination.vue +19 -19
  120. package/src/runtime/components/LibPalette/LibPalette.vue +3 -3
  121. package/src/runtime/components/LibPopup/LibPopup.stories.ts +2 -2
  122. package/src/runtime/components/LibPopup/LibPopup.vue +30 -66
  123. package/src/runtime/components/LibProgressBar/LibProgressBar.vue +3 -1
  124. package/src/runtime/components/LibRecorder/LibRecorder.vue +2 -2
  125. package/src/runtime/components/LibRoot/LibRoot.vue +14 -1
  126. package/src/runtime/components/LibSimpleInput/LibSimpleInput.stories.ts +1 -1
  127. package/src/runtime/components/LibSimpleInput/LibSimpleInput.vue +5 -7
  128. package/src/runtime/components/LibSuggestions/LibSuggestions.vue +42 -25
  129. package/src/runtime/components/LibTable/LibTable.vue +8 -8
  130. package/src/runtime/components/Scrolling.stories.ts +58 -0
  131. package/src/runtime/components/Template/NAME.vue +1 -1
  132. package/src/runtime/components/TestControls/TestControls.vue +1 -1
  133. package/src/runtime/components/index.ts +12 -12
  134. package/src/runtime/components/shared/props.ts +82 -19
  135. package/src/runtime/components/shared/storyHelpers/playInput.ts +6 -5
  136. package/src/runtime/components/shared/storyHelpers/playSuggestions.ts +25 -11
  137. package/src/runtime/composables/index.ts +5 -0
  138. package/src/runtime/composables/useDarkMode.ts +2 -2
  139. package/src/runtime/composables/useDivideAttrs.ts +1 -0
  140. package/src/runtime/composables/useDragWithThreshold.ts +108 -0
  141. package/src/runtime/composables/usePreHydrationValue.ts +30 -0
  142. package/src/runtime/composables/useSetupI18n.ts +8 -2
  143. package/src/runtime/composables/useSuggestions.ts +92 -45
  144. package/src/runtime/directives/vResizableCols.ts +3 -1
  145. package/src/runtime/helpers/NotificationHandler.ts +5 -0
  146. package/src/runtime/helpers/index.ts +3 -1
  147. package/src/runtime/types/index.ts +5 -0
  148. package/src/runtime/utils/notifyIfError.ts +45 -0
  149. package/dist/runtime/assets/style.css +0 -1
  150. package/dist/runtime/helpers/addValue.d.ts +0 -1
  151. package/dist/runtime/helpers/addValue.js +0 -8
  152. package/src/runtime/helpers/addValue.ts +0 -10
  153. /package/dist/runtime/components/{reset.stories.d.ts → Reset.stories.d.ts} +0 -0
  154. /package/dist/runtime/components/{reset.stories.js → Reset.stories.js} +0 -0
  155. /package/src/runtime/components/{reset.stories.ts → Reset.stories.ts} +0 -0
@@ -1,61 +1,84 @@
1
1
  <template>
2
2
  <lib-popup
3
+ class="color-input--popup"
3
4
  v-model="showPopup"
5
+ @close="$tempValue = undefined;emit('cancel')"
4
6
  >
5
7
  <template #button="{extractEl}">
8
+ <!-- <div -->
9
+ <!-- class=" -->
10
+ <!-- flex -->
11
+ <!-- w-full -->
12
+ <!-- border -->
13
+ <!-- " -->
14
+ <!-- v-extract-root-el="extractEl" -->
15
+ <!-- > -->
16
+
17
+ <!-- -->
6
18
  <lib-button
7
19
  :id="id ?? fallbackId"
8
20
  :class="twMerge(`
21
+ p-0
22
+ color-input--button
9
23
  flex flex-nowrap
24
+ min-w-4
25
+ overflow-hidden
26
+ [&_.button--label]:items-stretch
27
+ [&_.button--label]:gap-0
28
+ after:hidden
10
29
  `,
11
30
  ($attrs as any).class
12
31
  )"
13
- :aria-label="stringColor"
14
- :title="stringColor"
32
+ :aria-label="t('color-input.aria-and-title-prefix') + stringColor"
33
+ :title="t('color-input.aria-and-title-prefix') + stringColor"
15
34
  v-bind="{...$attrs, class: undefined}"
16
35
  v-extract-root-el="extractEl"
17
36
  @click="togglePopup"
18
37
  >
19
- <span class="color-label
20
- whitespace-nowrap
21
- pr-2
38
+ <template #label>
39
+ <div class="
40
+ color-input--swatch-wrapper
41
+ flex
42
+ w-full
22
43
  "
23
- >
24
- <slot>{{ t("color-picker.pick-color") }}</slot>
25
- </span>
26
- <div :class="`color-swatch
27
- rounded-xs
28
- px-1
29
- flex-1
30
- h-4
31
- w-8
32
- relative
33
- aspect-square
34
- before:content-['']
35
- before:absolute
36
- before:inset-0
37
- before:bg-transparency-squares
38
- before:z-[-1]
39
- `"
40
- :style="`background:${stringColor}`"
41
- />
44
+ >
45
+ <slot v-bind="{stringColor, classes:swatchClasses}">
46
+ <div :class="swatchClasses"
47
+ :style="`background:${stringColor}`"
48
+ />
49
+ </slot>
50
+ <slot
51
+ v-if="$tempValue"
52
+ v-bind="{tempStringColor, classes:swatchClasses}"
53
+ name="temp"
54
+ >
55
+ <div :class="swatchClasses"
56
+ :style="`background:${tempStringColor}`"
57
+ />
58
+ </slot>
59
+ </div>
60
+ </template>
42
61
  </lib-button>
43
62
  </template>
44
63
  <template #popup="{extractEl}">
45
- <lib-color-picker v-if="showPopup"
46
- :id="id ?? fallbackId"
47
- :allow-alpha="allowAlpha"
48
- v-model="tempValue"
49
- v-extract-root-el="extractEl"
50
- @save="$value = tempValue; showPopup = false"
51
- @cancel="showPopup = false"
52
- />
64
+ <div class="color-input--popup-wrapper p-5" v-extract-root-el="extractEl">
65
+ <lib-color-picker v-if="showPopup"
66
+ :id="id ?? fallbackId"
67
+ :allow-alpha="allowAlpha"
68
+ :custom-representation="customRepresentation"
69
+ :string-precision="stringPrecision"
70
+ v-model="internalTempValue"
71
+ v-model:temp-value="$tempValue"
72
+ @save="save"
73
+ @cancel="cancel"
74
+ />
75
+ </div>
53
76
  </template>
54
77
  </lib-popup>
55
78
  </template>
56
79
 
57
80
  <script setup lang="ts">
58
- import { colord } from "colord"
81
+ import Color from "colorjs.io"
59
82
  import { type ButtonHTMLAttributes,computed, type PropType, ref, useAttrs } from "vue"
60
83
 
61
84
  import { useInjectedI18n } from "../../composables/useInjectedI18n.js"
@@ -72,6 +95,19 @@ defineOptions({
72
95
  name: "lib-color-input",
73
96
  })
74
97
 
98
+ const swatchClasses = `
99
+ color-input--swatch
100
+ after:content-vertical-holder
101
+ min-w-4
102
+ flex-1
103
+ relative
104
+ before:content-['']
105
+ before:absolute
106
+ before:inset-0
107
+ before:bg-transparency-squares
108
+ before:z-[-1]
109
+ `
110
+
75
111
  const fallbackId = getFallbackId()
76
112
 
77
113
  const t = useInjectedI18n()
@@ -80,21 +116,52 @@ const props = withDefaults(defineProps<Props>(), {
80
116
  allowAlpha: true,
81
117
  border: true,
82
118
  copyTransform: (_val: HsvaColor, stringVal: string) => stringVal,
119
+ stringPrecision: 3,
120
+ customRepresentation: undefined,
83
121
  })
122
+ const emit = defineEmits<{
123
+ (e: "save"): void
124
+ (e: "cancel"): void
125
+ }>()
84
126
 
85
127
 
128
+ function save() {
129
+ $value.value = internalTempValue.value
130
+ showPopup.value = false
131
+ $tempValue.value = undefined
132
+ emit("save")
133
+ }
134
+ function cancel() {
135
+ showPopup.value = false
136
+ $tempValue.value = undefined
137
+ emit("cancel")
138
+ }
139
+
86
140
  const $attrs = useAttrs()
87
141
 
88
142
  const $value = defineModel<RgbaColor>({ required: false, default: () => ({ r: 0, g: 0, b: 0 }) })
89
- const stringColor = computed(() => colord($value.value).toRgbString())
90
- const tempValue = ref({ ...$value.value })
143
+ const $tempValue = defineModel<RgbaColor | undefined>("tempValue", { required: false, default: () => (undefined) })
144
+
145
+ const stringColor = computed(() => new Color("srgb", [
146
+ $value.value.r / 255,
147
+ $value.value.g / 255,
148
+ $value.value.b / 255,
149
+ ], $value.value.a ?? 1,).toString())
150
+
151
+ const tempStringColor = computed(() => $tempValue.value ? new Color("srgb", [
152
+ $tempValue.value.r / 255,
153
+ $tempValue.value.g / 255,
154
+ $tempValue.value.b / 255,
155
+ ], $tempValue.value.a ?? 1,).toString() : "")
156
+
157
+ const internalTempValue = ref({ ...$value.value })
91
158
 
92
159
  const showPopup = ref(false)
93
160
 
94
161
 
95
162
  const togglePopup = (): void => {
96
163
  if (showPopup.value) {
97
- $value.value = tempValue.value
164
+ $value.value = internalTempValue.value
98
165
  }
99
166
  showPopup.value = !showPopup.value
100
167
  }
@@ -109,7 +176,14 @@ type RealProps =
109
176
  & {
110
177
  allowAlpha?: boolean
111
178
  border?: boolean
179
+ /** See ColorPicker.copyTransform */
112
180
  copyTransform?: (val: HsvaColor, stringVal: string) => any
181
+ /** See ColorPicker.allowAlpha */
182
+ stringPrecision?: number
183
+ /** See ColorPicker.customRepresentation */
184
+ customRepresentation?: {
185
+ fromHsvaToString: (hsva: HsvaColor, includeAlpha: boolean) => string
186
+ }
113
187
  }
114
188
  interface Props
115
189
  extends
@@ -123,3 +197,4 @@ interface Props
123
197
  RealProps
124
198
  {}
125
199
  </script>
200
+
@@ -5,3 +5,5 @@ export default meta;
5
5
  type Story = StoryObj<typeof LibColorPicker>;
6
6
  export declare const Primary: Story;
7
7
  export declare const DoesNotAllowAlpha: Story;
8
+ export declare const WithExistingValue: Story;
9
+ export declare const CustomStringRepresentation: Story;
@@ -1,3 +1,4 @@
1
+ import Color from "colorjs.io";
1
2
  import { ref } from "vue";
2
3
  import LibColorPicker from "./LibColorPicker.vue";
3
4
  import * as components from "../index.js";
@@ -11,12 +12,8 @@ export const Primary = {
11
12
  render: (args) => ({
12
13
  components,
13
14
  setup: () => {
14
- const color = ref({
15
- r: 0,
16
- g: 0,
17
- b: 0
18
- /* , a: 0.5 */
19
- });
15
+ const color = ref({ r: 0, g: 0, b: 0, ...args.modelValue });
16
+ delete args.modelValue;
20
17
  const handleChange = (e) => {
21
18
  color.value = { ...e };
22
19
  };
@@ -31,15 +28,15 @@ export const Primary = {
31
28
  };
32
29
  },
33
30
  template: `
34
- <test-wrapper :outline="args.outline">
31
+ <lib-root :outline="args.outline">
35
32
  {{args.color}}
36
33
  <lib-color-picker
37
- :allowAlpha="args.allowAlpha"
38
34
  :modelValue="args.color.value"
35
+ v-bind="args"
39
36
  @update:modelValue="handleChange"
40
37
  >
41
38
  </lib-color-picker>
42
- </test-wrapper>
39
+ </lib-root>
43
40
  `
44
41
  })
45
42
  };
@@ -49,3 +46,23 @@ export const DoesNotAllowAlpha = {
49
46
  allowAlpha: false
50
47
  }
51
48
  };
49
+ export const WithExistingValue = {
50
+ ...Primary,
51
+ args: {
52
+ modelValue: { r: 255, g: 0, b: 0 }
53
+ }
54
+ };
55
+ export const CustomStringRepresentation = {
56
+ ...Primary,
57
+ args: {
58
+ allowAlpha: false,
59
+ customRepresentation: {
60
+ fromHsvaToString: (hsva, includeAlpha) => new Color(
61
+ "hsv",
62
+ [hsva.h, hsva.s, hsva.v],
63
+ includeAlpha ? hsva.a : 1
64
+ // this takes care of the correct hex format
65
+ ).toString({ format: "hex" })
66
+ }
67
+ }
68
+ };