@histoire/controls 0.3.1 → 0.3.2

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.
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, import("vue").EmitsOptions, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}>;
2
+ export default _default;
@@ -0,0 +1,43 @@
1
+ import { PropType } from 'vue';
2
+ export interface HstSelectOptions {
3
+ label: string;
4
+ value: string;
5
+ }
6
+ declare const _default: import("vue").DefineComponent<{
7
+ title: {
8
+ type: StringConstructor;
9
+ default: string;
10
+ };
11
+ modelValue: {
12
+ type: StringConstructor;
13
+ default: any;
14
+ };
15
+ options: {
16
+ type: PropType<string[] | HstSelectOptions[]>;
17
+ required: true;
18
+ default: () => any[];
19
+ };
20
+ }, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
21
+ 'update:modelValue': (newValue: string) => true;
22
+ }, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
23
+ title: {
24
+ type: StringConstructor;
25
+ default: string;
26
+ };
27
+ modelValue: {
28
+ type: StringConstructor;
29
+ default: any;
30
+ };
31
+ options: {
32
+ type: PropType<string[] | HstSelectOptions[]>;
33
+ required: true;
34
+ default: () => any[];
35
+ };
36
+ }>> & {
37
+ "onUpdate:modelValue"?: (newValue: string) => any;
38
+ }, {
39
+ title: string;
40
+ modelValue: string;
41
+ options: string[] | HstSelectOptions[];
42
+ }>;
43
+ export default _default;
package/dist/index.es.js CHANGED
@@ -29,7 +29,7 @@ var __objRest = (source, exclude) => {
29
29
  }
30
30
  return target;
31
31
  };
32
- import { pushScopeId, popScopeId, defineComponent, nextTick, openBlock, createBlock, withScopeId, resolveComponent, createElementBlock, normalizeClass, normalizeStyle, withKeys, createElementVNode, Fragment, renderSlot, createCommentVNode, mergeProps, withCtx, createVNode, ref, createApp, h, toDisplayString, withDirectives, createTextVNode, unref, computed, watch, withModifiers, onUnmounted, isRef, vModelText, getCurrentScope, onScopeDispose, renderList } from "vue";
32
+ import { pushScopeId, popScopeId, defineComponent, nextTick, openBlock, createBlock, withScopeId, resolveComponent, createElementBlock, normalizeClass, normalizeStyle, withKeys, createElementVNode, Fragment, renderSlot, createCommentVNode, mergeProps, withCtx, createVNode, ref, createApp, h, toDisplayString, withDirectives, createTextVNode, unref, computed, watch, withModifiers, onUnmounted, isRef, vModelText, renderList, getCurrentScope, onScopeDispose } from "vue";
33
33
  function getBasePlacement(placement) {
34
34
  return placement.split("-")[0];
35
35
  }
@@ -2523,7 +2523,7 @@ defineComponent(__spreadProps2(__spreadValues2({}, PrivatePopperWrapper), {
2523
2523
  name: "VTooltip",
2524
2524
  vPopperTheme: "tooltip"
2525
2525
  }));
2526
- const _sfc_main$9 = defineComponent({
2526
+ const _sfc_main$a = defineComponent({
2527
2527
  name: "VTooltipDirective",
2528
2528
  components: {
2529
2529
  Popper: PrivatePopper(),
@@ -2614,8 +2614,8 @@ const _sfc_main$9 = defineComponent({
2614
2614
  }
2615
2615
  }
2616
2616
  });
2617
- const _hoisted_1$7 = ["innerHTML"];
2618
- const _hoisted_2$5 = ["textContent"];
2617
+ const _hoisted_1$8 = ["innerHTML"];
2618
+ const _hoisted_2$6 = ["textContent"];
2619
2619
  function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
2620
2620
  const _component_PopperContent = resolveComponent("PopperContent");
2621
2621
  const _component_Popper = resolveComponent("Popper");
@@ -2658,10 +2658,10 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
2658
2658
  _ctx.html ? (openBlock(), createElementBlock("div", {
2659
2659
  key: 0,
2660
2660
  innerHTML: _ctx.finalContent
2661
- }, null, 8, _hoisted_1$7)) : (openBlock(), createElementBlock("div", {
2661
+ }, null, 8, _hoisted_1$8)) : (openBlock(), createElementBlock("div", {
2662
2662
  key: 1,
2663
2663
  textContent: toDisplayString(_ctx.finalContent)
2664
- }, null, 8, _hoisted_2$5))
2664
+ }, null, 8, _hoisted_2$6))
2665
2665
  ]),
2666
2666
  _: 2
2667
2667
  }, 1032, ["class", "popper-id", "theme", "shown", "mounted", "skip-transition", "auto-hide", "handle-resize", "classes", "result", "onHide", "onResize"])
@@ -2669,7 +2669,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
2669
2669
  _: 1
2670
2670
  }, 16, ["theme", "popper-node", "onApplyShow", "onApplyHide"]);
2671
2671
  }
2672
- var PrivateTooltipDirective = /* @__PURE__ */ _export_sfc(_sfc_main$9, [["render", _sfc_render]]);
2672
+ var PrivateTooltipDirective = /* @__PURE__ */ _export_sfc(_sfc_main$a, [["render", _sfc_render]]);
2673
2673
  const TARGET_CLASS = "v-popper--has-tooltip";
2674
2674
  function getPlacement(options2, modifiers) {
2675
2675
  let result = options2.placement;
@@ -2794,20 +2794,20 @@ var PrivateVTooltip = {
2794
2794
  }
2795
2795
  };
2796
2796
  const VTooltip = PrivateVTooltip;
2797
- const _hoisted_1$6 = { class: "htw-p-2 hover:htw-bg-primary-100 dark:hover:htw-bg-primary-800 htw-flex htw-gap-2 htw-flex-wrap" };
2798
- const _hoisted_2$4 = { class: "htw-w-28 htw-whitespace-nowrap htw-text-ellipsis htw-overflow-hidden htw-shrink-0" };
2797
+ const _hoisted_1$7 = { class: "htw-p-2 hover:htw-bg-primary-100 dark:hover:htw-bg-primary-800 htw-flex htw-gap-2 htw-flex-wrap" };
2798
+ const _hoisted_2$5 = { class: "htw-w-28 htw-whitespace-nowrap htw-text-ellipsis htw-overflow-hidden htw-shrink-0" };
2799
2799
  const _hoisted_3$4 = { class: "htw-block htw-grow" };
2800
- const __default__$8 = {
2800
+ const __default__$9 = {
2801
2801
  name: "HstWrapper"
2802
2802
  };
2803
- const _sfc_main$8 = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues({}, __default__$8), {
2803
+ const _sfc_main$9 = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues({}, __default__$9), {
2804
2804
  props: {
2805
2805
  title: null
2806
2806
  },
2807
2807
  setup(__props) {
2808
2808
  return (_ctx, _cache) => {
2809
- return openBlock(), createElementBlock("label", _hoisted_1$6, [
2810
- withDirectives((openBlock(), createElementBlock("span", _hoisted_2$4, [
2809
+ return openBlock(), createElementBlock("label", _hoisted_1$7, [
2810
+ withDirectives((openBlock(), createElementBlock("span", _hoisted_2$5, [
2811
2811
  createTextVNode(toDisplayString(__props.title), 1)
2812
2812
  ])), [
2813
2813
  [unref(VTooltip), {
@@ -2823,18 +2823,18 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues
2823
2823
  };
2824
2824
  }
2825
2825
  }));
2826
- const _hoisted_1$5 = { class: "htw-text-white htw-w-[16px] htw-h-[16px] htw-relative" };
2827
- const _hoisted_2$3 = {
2826
+ const _hoisted_1$6 = { class: "htw-text-white htw-w-[16px] htw-h-[16px] htw-relative" };
2827
+ const _hoisted_2$4 = {
2828
2828
  width: "16",
2829
2829
  height: "16",
2830
2830
  viewBox: "0 0 24 24",
2831
2831
  class: "htw-relative htw-z-10"
2832
2832
  };
2833
2833
  const _hoisted_3$3 = ["stroke-dasharray", "stroke-dashoffset"];
2834
- const __default__$7 = {
2834
+ const __default__$8 = {
2835
2835
  name: "HstCheckbox"
2836
2836
  };
2837
- const _sfc_main$7 = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues({}, __default__$7), {
2837
+ const _sfc_main$8 = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues({}, __default__$8), {
2838
2838
  props: {
2839
2839
  modelValue: { type: Boolean },
2840
2840
  title: null
@@ -2858,7 +2858,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues
2858
2858
  dasharray.value = (_c = (_b2 = (_a2 = path.value).getTotalLength) == null ? void 0 : _b2.call(_a2)) != null ? _c : 21.21;
2859
2859
  });
2860
2860
  return (_ctx, _cache) => {
2861
- return openBlock(), createBlock(_sfc_main$8, {
2861
+ return openBlock(), createBlock(_sfc_main$9, {
2862
2862
  role: "checkbox",
2863
2863
  tabindex: "0",
2864
2864
  class: "htw-cursor-pointer htw-items-center",
@@ -2870,13 +2870,13 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues
2870
2870
  ]
2871
2871
  }, {
2872
2872
  default: withCtx(() => [
2873
- createElementVNode("div", _hoisted_1$5, [
2873
+ createElementVNode("div", _hoisted_1$6, [
2874
2874
  createElementVNode("div", {
2875
2875
  class: normalizeClass(["htw-border htw-border-solid group-active:htw-bg-gray-500/20 htw-rounded-sm htw-box-border htw-absolute htw-inset-0 htw-transition-border htw-duration-150 htw-ease-out", [
2876
2876
  __props.modelValue ? "htw-border-primary-500 htw-border-8" : "htw-border-black/25 dark:htw-border-white/25 htw-delay-150"
2877
2877
  ]])
2878
2878
  }, null, 2),
2879
- (openBlock(), createElementBlock("svg", _hoisted_2$3, [
2879
+ (openBlock(), createElementBlock("svg", _hoisted_2$4, [
2880
2880
  createElementVNode("path", {
2881
2881
  ref_key: "path",
2882
2882
  ref: path,
@@ -2899,11 +2899,11 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues
2899
2899
  };
2900
2900
  }
2901
2901
  }));
2902
- const _hoisted_1$4 = ["value"];
2903
- const __default__$6 = {
2902
+ const _hoisted_1$5 = ["value"];
2903
+ const __default__$7 = {
2904
2904
  name: "HstText"
2905
2905
  };
2906
- const _sfc_main$6 = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues({}, __default__$6), {
2906
+ const _sfc_main$7 = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues({}, __default__$7), {
2907
2907
  props: {
2908
2908
  title: null,
2909
2909
  modelValue: null
@@ -2914,7 +2914,7 @@ const _sfc_main$6 = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues
2914
2914
  setup(__props, { emit }) {
2915
2915
  const input = ref();
2916
2916
  return (_ctx, _cache) => {
2917
- return openBlock(), createBlock(_sfc_main$8, {
2917
+ return openBlock(), createBlock(_sfc_main$9, {
2918
2918
  title: __props.title,
2919
2919
  class: normalizeClass(["htw-cursor-text htw-items-center", _ctx.$attrs.class]),
2920
2920
  style: normalizeStyle(_ctx.$attrs.style),
@@ -2929,18 +2929,18 @@ const _sfc_main$6 = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues
2929
2929
  value: __props.modelValue,
2930
2930
  class: "htw-text-inherit htw-bg-transparent htw-w-full htw-outline-none htw-px-2 htw-py-1 -htw-my-1 htw-border htw-border-solid htw-border-black/25 dark:htw-border-white/25 focus:htw-border-primary-500 dark:focus:htw-border-primary-500 htw-rounded-sm",
2931
2931
  onInput: _cache[0] || (_cache[0] = ($event) => emit("update:modelValue", $event.target.value))
2932
- }), null, 16, _hoisted_1$4)
2932
+ }), null, 16, _hoisted_1$5)
2933
2933
  ]),
2934
2934
  _: 1
2935
2935
  }, 8, ["title", "class", "style"]);
2936
2936
  };
2937
2937
  }
2938
2938
  }));
2939
- const __default__$5 = {
2939
+ const __default__$6 = {
2940
2940
  name: "HstNumber",
2941
2941
  inheritAttrs: false
2942
2942
  };
2943
- const _sfc_main$5 = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues({}, __default__$5), {
2943
+ const _sfc_main$6 = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues({}, __default__$6), {
2944
2944
  props: {
2945
2945
  title: null,
2946
2946
  modelValue: null
@@ -2987,7 +2987,7 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues
2987
2987
  stopDragging();
2988
2988
  });
2989
2989
  return (_ctx, _cache) => {
2990
- return openBlock(), createBlock(_sfc_main$8, {
2990
+ return openBlock(), createBlock(_sfc_main$9, {
2991
2991
  class: normalizeClass(["htw-cursor-ew-resize htw-items-center", [
2992
2992
  _ctx.$attrs.class,
2993
2993
  { "htw-select-none": isDragging.value }
@@ -3021,12 +3021,12 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues
3021
3021
  };
3022
3022
  }
3023
3023
  }));
3024
- const _hoisted_1$3 = ["value"];
3025
- const __default__$4 = {
3024
+ const _hoisted_1$4 = ["value"];
3025
+ const __default__$5 = {
3026
3026
  name: "HstTextarea",
3027
3027
  inheritAttrs: false
3028
3028
  };
3029
- const _sfc_main$4 = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues({}, __default__$4), {
3029
+ const _sfc_main$5 = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues({}, __default__$5), {
3030
3030
  props: {
3031
3031
  title: null,
3032
3032
  modelValue: null
@@ -3037,7 +3037,7 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues
3037
3037
  setup(__props, { emit }) {
3038
3038
  const input = ref();
3039
3039
  return (_ctx, _cache) => {
3040
- return openBlock(), createBlock(_sfc_main$8, {
3040
+ return openBlock(), createBlock(_sfc_main$9, {
3041
3041
  title: __props.title,
3042
3042
  class: normalizeClass(["htw-cursor-text", _ctx.$attrs.class]),
3043
3043
  style: normalizeStyle(_ctx.$attrs.style),
@@ -3051,7 +3051,64 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues
3051
3051
  value: __props.modelValue,
3052
3052
  class: "htw-text-inherit htw-bg-transparent htw-w-full htw-outline-none htw-px-2 htw-py-1 -htw-my-1 htw-border htw-border-solid htw-border-black/25 dark:htw-border-white/25 focus:htw-border-primary-500 dark:focus:htw-border-primary-500 htw-rounded-sm htw-box-border htw-resize-y htw-min-h-[26px]",
3053
3053
  onInput: _cache[0] || (_cache[0] = ($event) => emit("update:modelValue", $event.target.value))
3054
- }), null, 16, _hoisted_1$3)
3054
+ }), null, 16, _hoisted_1$4)
3055
+ ]),
3056
+ _: 1
3057
+ }, 8, ["title", "class", "style"]);
3058
+ };
3059
+ }
3060
+ }));
3061
+ const _hoisted_1$3 = ["value"];
3062
+ const _hoisted_2$3 = ["value"];
3063
+ const __default__$4 = {
3064
+ name: "HstSelect"
3065
+ };
3066
+ const _sfc_main$4 = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues({}, __default__$4), {
3067
+ props: {
3068
+ title: {
3069
+ type: String,
3070
+ default: ""
3071
+ },
3072
+ modelValue: {
3073
+ type: String,
3074
+ default: null
3075
+ },
3076
+ options: {
3077
+ type: Array,
3078
+ required: true,
3079
+ default: () => []
3080
+ }
3081
+ },
3082
+ emits: {
3083
+ "update:modelValue": (newValue) => true
3084
+ },
3085
+ setup(__props, { emit }) {
3086
+ const props = __props;
3087
+ const formattedOtions = computed(() => props.options.map((option) => typeof option === "string" ? { label: option, value: option } : option));
3088
+ const select = ref();
3089
+ return (_ctx, _cache) => {
3090
+ return openBlock(), createBlock(_sfc_main$9, {
3091
+ title: __props.title,
3092
+ class: normalizeClass(["htw-cursor-text htw-items-center", _ctx.$attrs.class]),
3093
+ style: normalizeStyle(_ctx.$attrs.style),
3094
+ onClick: _cache[1] || (_cache[1] = ($event) => select.value.focus())
3095
+ }, {
3096
+ default: withCtx(() => [
3097
+ createElementVNode("select", {
3098
+ ref_key: "select",
3099
+ ref: select,
3100
+ class: "htw-text-inherit htw-bg-transparent htw-w-full htw-outline-none htw-px-2 htw-py-1 -htw-my-1 htw-border htw-border-solid htw-border-black/25 dark:htw-border-white/25 focus:htw-border-primary-500 dark:focus:htw-border-primary-500 htw-rounded-sm",
3101
+ value: __props.modelValue,
3102
+ onInput: _cache[0] || (_cache[0] = ($event) => emit("update:modelValue", $event.target.value))
3103
+ }, [
3104
+ (openBlock(true), createElementBlock(Fragment, null, renderList(unref(formattedOtions), ({ label, value }) => {
3105
+ return openBlock(), createElementBlock("option", mergeProps(__spreadProps(__spreadValues({}, _ctx.$attrs), { class: null, style: null }), {
3106
+ key: label,
3107
+ class: "dark:htw-bg-gray-600",
3108
+ value
3109
+ }), toDisplayString(label), 17, _hoisted_2$3);
3110
+ }), 128))
3111
+ ], 40, _hoisted_1$3)
3055
3112
  ]),
3056
3113
  _: 1
3057
3114
  }, 8, ["title", "class", "style"]);
@@ -5265,19 +5322,20 @@ const _sfc_main = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues({
5265
5322
  };
5266
5323
  }
5267
5324
  }));
5268
- const HstCheckbox = _sfc_main$7;
5269
- const HstText = _sfc_main$6;
5270
- const HstNumber = _sfc_main$5;
5271
- const HstTextarea = _sfc_main$4;
5325
+ const HstCheckbox = _sfc_main$8;
5326
+ const HstText = _sfc_main$7;
5327
+ const HstNumber = _sfc_main$6;
5328
+ const HstTextarea = _sfc_main$5;
5272
5329
  const HstColorShades = _sfc_main$2;
5273
5330
  const HstTokenList = _sfc_main$1;
5274
5331
  const HstTokenGrid = _sfc_main;
5275
5332
  const HstCopyIcon = _sfc_main$3;
5276
5333
  function registerVueComponents(app) {
5277
- app.component("HstCheckbox", _sfc_main$7);
5278
- app.component("HstText", _sfc_main$6);
5279
- app.component("HstNumber", _sfc_main$5);
5280
- app.component("HstTextarea", _sfc_main$4);
5334
+ app.component("HstCheckbox", _sfc_main$8);
5335
+ app.component("HstText", _sfc_main$7);
5336
+ app.component("HstNumber", _sfc_main$6);
5337
+ app.component("HstSelect", _sfc_main$4);
5338
+ app.component("HstTextarea", _sfc_main$5);
5281
5339
  app.component("HstColorShades", _sfc_main$2);
5282
5340
  app.component("HstTokenList", _sfc_main$1);
5283
5341
  app.component("HstTokenGrid", _sfc_main);
@@ -505,6 +505,11 @@
505
505
  background-color:transparent
506
506
  }
507
507
 
508
+ .htw-bg-gray-50{
509
+ --tw-bg-opacity:1;
510
+ background-color:rgb(250 250 250 / var(--tw-bg-opacity))
511
+ }
512
+
508
513
  .htw-stroke-white{
509
514
  stroke:#fff
510
515
  }
@@ -517,6 +522,10 @@
517
522
  padding:0.5rem
518
523
  }
519
524
 
525
+ .htw-p-4{
526
+ padding:1rem
527
+ }
528
+
520
529
  .htw-py-1{
521
530
  padding-top:0.25rem;
522
531
  padding-bottom:0.25rem
@@ -536,6 +545,11 @@
536
545
  line-height:1
537
546
  }
538
547
 
548
+ .htw-text-xs{
549
+ font-size:0.75rem;
550
+ line-height:1rem
551
+ }
552
+
539
553
  .htw-text-white{
540
554
  --tw-text-opacity:1;
541
555
  color:rgb(255 255 255 / var(--tw-text-opacity))
@@ -637,6 +651,11 @@ body {
637
651
  background-color:rgb(0 0 0 / var(--tw-bg-opacity))
638
652
  }
639
653
 
654
+ .htw-dark .dark\:htw-bg-gray-600{
655
+ --tw-bg-opacity:1;
656
+ background-color:rgb(82 82 91 / var(--tw-bg-opacity))
657
+ }
658
+
640
659
  .htw-dark .dark\:hover\:htw-bg-primary-800:hover{
641
660
  --tw-bg-opacity:1;
642
661
  background-color:rgb(6 95 70 / var(--tw-bg-opacity))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@histoire/controls",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "Prebuilt controls components",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -44,7 +44,7 @@
44
44
  "autoprefixer": "^10.4.4",
45
45
  "concurrently": "^7.1.0",
46
46
  "floating-vue": "^2.0.0-beta.14",
47
- "histoire": "0.3.1",
47
+ "histoire": "0.3.2",
48
48
  "postcss": "^8.4.12",
49
49
  "postcss-import": "^14.1.0",
50
50
  "tailwindcss": "^3.0.23",
@@ -0,0 +1,110 @@
1
+ <script lang="ts" setup>
2
+ import HstSelect from './HstSelect.vue'
3
+
4
+ const options = [
5
+ { label: 'Crash Bandicoot', value: 'crash-bandicoot' },
6
+ { label: 'The Last of Us', value: 'the-last-of-us' },
7
+ { label: 'Ghost of Tsushima', value: 'ghost-of-tsushima' },
8
+ ]
9
+
10
+ const flatOptions = options.map(option => option.label)
11
+
12
+ function initState () {
13
+ return {
14
+ label: 'My really long label',
15
+ select: 'crash-bandicoot',
16
+ }
17
+ }
18
+ </script>
19
+
20
+ <template>
21
+ <Story
22
+ title="HstSelect"
23
+ :layout="{
24
+ type: 'grid',
25
+ width: '100%',
26
+ }"
27
+ >
28
+ <Variant
29
+ title="default"
30
+ :init-state="initState"
31
+ >
32
+ <template #default="{ state }">
33
+ <HstSelect
34
+ v-model="state.select"
35
+ :title="state.label"
36
+ :options="options"
37
+ />
38
+ </template>
39
+
40
+ <template #controls="{ state }">
41
+ <HstSelect
42
+ v-model="state.select"
43
+ title="Select"
44
+ :options="options"
45
+ />
46
+ </template>
47
+ </Variant>
48
+
49
+ <Variant
50
+ title="no-label"
51
+ :init-state="initState"
52
+ >
53
+ <template #default="{ state }">
54
+ <HstSelect
55
+ v-model="state.select"
56
+ :options="options"
57
+ />
58
+ </template>
59
+ <template #controls="{ state }">
60
+ <HstSelect
61
+ v-model="state.select"
62
+ title="Select"
63
+ :options="options"
64
+ />
65
+ </template>
66
+ </Variant>
67
+
68
+ <Variant
69
+ title="options-as-array-of-objects"
70
+ :init-state="initState"
71
+ >
72
+ <template #default="{ state }">
73
+ <pre class="htw-text-xs htw-bg-gray-50 dark:htw-bg-gray-600 htw-rounded htw-p-4">{{ options }}</pre>
74
+ <HstSelect
75
+ v-model="state.select"
76
+ title="Games"
77
+ :options="options"
78
+ />
79
+ </template>
80
+ <template #controls="{ state }">
81
+ <HstSelect
82
+ v-model="state.select"
83
+ title="Games"
84
+ :options="options"
85
+ />
86
+ </template>
87
+ </Variant>
88
+
89
+ <Variant
90
+ title="options-as-array-of-strings"
91
+ :init-state="initState"
92
+ >
93
+ <template #default="{ state }">
94
+ <pre class="htw-text-xs htw-bg-gray-50 dark:htw-bg-gray-600 htw-rounded htw-p-4">{{ flatOptions }}</pre>
95
+ <HstSelect
96
+ v-model="state.select"
97
+ title="Select"
98
+ :options="flatOptions"
99
+ />
100
+ </template>
101
+ <template #controls="{ state }">
102
+ <HstSelect
103
+ v-model="state.select"
104
+ title="Select"
105
+ :options="flatOptions"
106
+ />
107
+ </template>
108
+ </Variant>
109
+ </Story>
110
+ </template>
@@ -0,0 +1,67 @@
1
+ <script lang="ts">
2
+ export default {
3
+ name: 'HstSelect',
4
+ }
5
+ </script>
6
+
7
+ <script lang="ts" setup>
8
+ import { ref, computed, ComputedRef, PropType } from 'vue'
9
+ import HstWrapper from '../HstWrapper.vue'
10
+
11
+ export interface HstSelectOptions {
12
+ label: string
13
+ value: string
14
+ }
15
+
16
+ const props = defineProps({
17
+ title: {
18
+ type: String,
19
+ default: '',
20
+ },
21
+ modelValue: {
22
+ type: String,
23
+ default: null,
24
+ },
25
+ options: {
26
+ type: Array as PropType<HstSelectOptions[] | string[]>,
27
+ required: true,
28
+ default: () => [],
29
+ },
30
+ })
31
+
32
+ const formattedOtions: ComputedRef<HstSelectOptions[]> =
33
+ computed(() => props.options.map(option => typeof option === 'string' ? { label: option, value: option } as HstSelectOptions : option as HstSelectOptions))
34
+
35
+ const emit = defineEmits({
36
+ 'update:modelValue': (newValue: string) => true,
37
+ })
38
+
39
+ const select = ref<HTMLInputElement>()
40
+ </script>
41
+
42
+ <template>
43
+ <HstWrapper
44
+ :title="title"
45
+ class="htw-cursor-text htw-items-center"
46
+ :class="$attrs.class"
47
+ :style="$attrs.style"
48
+ @click="select.focus()"
49
+ >
50
+ <select
51
+ ref="select"
52
+ class="htw-text-inherit htw-bg-transparent htw-w-full htw-outline-none htw-px-2 htw-py-1 -htw-my-1 htw-border htw-border-solid htw-border-black/25 dark:htw-border-white/25 focus:htw-border-primary-500 dark:focus:htw-border-primary-500 htw-rounded-sm"
53
+ :value="modelValue"
54
+ @input="emit('update:modelValue', ($event.target as HTMLInputElement).value)"
55
+ >
56
+ <option
57
+ v-for="{ label, value } in formattedOtions"
58
+ v-bind="{ ...$attrs, class: null, style: null }"
59
+ :key="label"
60
+ class="dark:htw-bg-gray-600"
61
+ :value="value"
62
+ >
63
+ {{ label }}
64
+ </option>
65
+ </select>
66
+ </HstWrapper>
67
+ </template>
package/src/index.ts CHANGED
@@ -3,6 +3,7 @@ import HstCheckboxVue from './components/checkbox/HstCheckbox.vue'
3
3
  import HstTextVue from './components/text/HstText.vue'
4
4
  import HstNumberVue from './components/number/HstNumber.vue'
5
5
  import HstTextareaVue from './components/textarea/HstTextarea.vue'
6
+ import HstSelectVue from './components/select/HstSelect.vue'
6
7
  import HstColorShadesVue from './components/design-tokens/HstColorShades.vue'
7
8
  import HstTokenListVue from './components/design-tokens/HstTokenList.vue'
8
9
  import HstTokenGridVue from './components/design-tokens/HstTokenGrid.vue'
@@ -21,6 +22,7 @@ export function registerVueComponents (app: App) {
21
22
  app.component('HstCheckbox', HstCheckboxVue)
22
23
  app.component('HstText', HstTextVue)
23
24
  app.component('HstNumber', HstNumberVue)
25
+ app.component('HstSelect', HstSelectVue)
24
26
  app.component('HstTextarea', HstTextareaVue)
25
27
  app.component('HstColorShades', HstColorShadesVue)
26
28
  app.component('HstTokenList', HstTokenListVue)