@toife/vue 3.1.3 → 3.1.5

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 (157) hide show
  1. package/README.md +1 -1
  2. package/package.json +1 -1
  3. package/src/components/action/action.scss +1 -1
  4. package/src/components/action/action.vue +5 -5
  5. package/src/components/app/app.scss +2 -2
  6. package/src/components/app/app.type.ts +6 -0
  7. package/src/components/app/app.vue +8 -2
  8. package/src/components/avatar/avatar.scss +6 -4
  9. package/src/components/avatar/avatar.vue +6 -6
  10. package/src/components/button/button.scss +19 -16
  11. package/src/components/button/button.type.ts +3 -1
  12. package/src/components/button/button.vue +7 -7
  13. package/src/components/cable/cable.vue +2 -2
  14. package/src/components/card/card/card.scss +5 -3
  15. package/src/components/card/card/card.vue +5 -5
  16. package/src/components/card/card-body/card-body.scss +2 -2
  17. package/src/components/card/card-body/card-body.vue +2 -2
  18. package/src/components/card/card-footer/card-footer.scss +3 -3
  19. package/src/components/card/card-footer/card-footer.vue +2 -2
  20. package/src/components/card/card-header/card-header.scss +3 -3
  21. package/src/components/card/card-header/card-header.vue +2 -2
  22. package/src/components/checkbox/checkbox.html +1 -1
  23. package/src/components/checkbox/checkbox.scss +27 -27
  24. package/src/components/checkbox/checkbox.type.ts +4 -0
  25. package/src/components/checkbox/checkbox.vue +8 -6
  26. package/src/components/collapse/collapse.html +1 -1
  27. package/src/components/collapse/collapse.scss +2 -2
  28. package/src/components/collapse/collapse.vue +9 -9
  29. package/src/components/container/container.vue +2 -2
  30. package/src/components/decision-modal/decision-modal.scss +12 -10
  31. package/src/components/decision-modal/decision-modal.vue +8 -8
  32. package/src/components/divider/divider.scss +2 -2
  33. package/src/components/divider/divider.vue +4 -4
  34. package/src/components/dropdown/dropdown.scss +8 -5
  35. package/src/components/dropdown/dropdown.type.ts +4 -1
  36. package/src/components/dropdown/dropdown.vue +8 -6
  37. package/src/components/field/field.type.ts +4 -4
  38. package/src/components/field/outline/outline.scss +24 -21
  39. package/src/components/field/outline/outline.vue +26 -18
  40. package/src/components/form-group/form-group.vue +2 -2
  41. package/src/components/gesture-indicator/gesture-indicator.scss +4 -2
  42. package/src/components/gesture-indicator/gesture-indicator.vue +4 -4
  43. package/src/components/image/image.vue +12 -5
  44. package/src/components/index.ts +1 -0
  45. package/src/components/layout/flex/flex.scss +0 -2
  46. package/src/components/layout/flex/flex.vue +8 -8
  47. package/src/components/layout/flex-item/flex-item.html +1 -0
  48. package/src/components/layout/flex-item/flex-item.scss +48 -0
  49. package/src/components/layout/flex-item/flex-item.type.ts +11 -0
  50. package/src/components/layout/flex-item/flex-item.vue +27 -0
  51. package/src/components/layout/flex-item/index.ts +2 -0
  52. package/src/components/layout/grid/grid.scss +0 -2
  53. package/src/components/layout/grid/grid.vue +6 -6
  54. package/src/components/layout/grid-item/grid-item.html +1 -0
  55. package/src/components/layout/grid-item/grid-item.scss +49 -0
  56. package/src/components/layout/grid-item/grid-item.type.ts +14 -0
  57. package/src/components/layout/grid-item/grid-item.vue +27 -0
  58. package/src/components/layout/grid-item/index.ts +2 -0
  59. package/src/components/layout/index.ts +2 -1
  60. package/src/components/modal/modal.scss +4 -2
  61. package/src/components/modal/modal.vue +68 -5
  62. package/src/components/page/page.vue +2 -2
  63. package/src/components/present/present.scss +3 -3
  64. package/src/components/present/present.vue +14 -14
  65. package/src/components/radio/radio/radio.html +1 -1
  66. package/src/components/radio/radio/radio.scss +25 -18
  67. package/src/components/radio/radio/radio.type.ts +4 -0
  68. package/src/components/radio/radio/radio.vue +7 -5
  69. package/src/components/radio/radio-group/radio-group.vue +2 -2
  70. package/src/components/refresher/refresher.html +1 -4
  71. package/src/components/refresher/refresher.scss +8 -26
  72. package/src/components/refresher/refresher.vue +2 -16
  73. package/src/components/route/route-navigator/route-navigator.scss +2 -2
  74. package/src/components/route/route-navigator/route-navigator.vue +10 -13
  75. package/src/components/route/route-wrapper/route-wrapper.composable.ts +5 -15
  76. package/src/components/route/route-wrapper/route-wrapper.type.ts +0 -4
  77. package/src/components/route/route-wrapper/route-wrapper.vue +4 -12
  78. package/src/components/route/route.type.ts +0 -1
  79. package/src/components/segmented-field/segmented-field.html +1 -1
  80. package/src/components/segmented-field/segmented-field.scss +2 -2
  81. package/src/components/segmented-field/segmented-field.vue +8 -8
  82. package/src/components/select/select.html +2 -2
  83. package/src/components/select/select.scss +10 -10
  84. package/src/components/select/select.vue +10 -10
  85. package/src/components/skeleton/skeleton.scss +3 -1
  86. package/src/components/skeleton/skeleton.vue +7 -7
  87. package/src/components/slide-range/index.ts +2 -0
  88. package/src/components/slide-range/slide-range.html +19 -0
  89. package/src/components/slide-range/slide-range.scss +161 -0
  90. package/src/components/slide-range/slide-range.type.ts +16 -0
  91. package/src/components/slide-range/slide-range.vue +229 -0
  92. package/src/components/switch/switch.html +1 -1
  93. package/src/components/switch/switch.scss +29 -38
  94. package/src/components/switch/switch.type.ts +6 -0
  95. package/src/components/switch/switch.vue +24 -8
  96. package/src/components/tabs/tab/tab.html +1 -1
  97. package/src/components/tabs/tab/tab.scss +13 -0
  98. package/src/components/tabs/tab/tab.vue +4 -2
  99. package/src/components/tabs/tabs/index.ts +1 -0
  100. package/src/components/tabs/tabs/tabs.scss +194 -122
  101. package/src/components/tabs/tabs/tabs.type.ts +5 -2
  102. package/src/components/tabs/tabs/tabs.vue +47 -27
  103. package/src/components/toast/toast/toast.vue +2 -2
  104. package/src/components/toast/toast-content/toast-content.scss +6 -5
  105. package/src/components/toast/toast-content/toast-content.vue +5 -5
  106. package/src/components/toolbar/toolbar.scss +4 -4
  107. package/src/components/toolbar/toolbar.type.ts +1 -1
  108. package/src/components/toolbar/toolbar.vue +7 -7
  109. package/src/factory.ts +108 -50
  110. package/src/index.ts +1 -1
  111. package/src/type.ts +2 -1
  112. package/src/utils/style/index.ts +9 -9
  113. package/src/utils/style.md +9 -9
  114. package/src/components/action/action.md +0 -115
  115. package/src/components/app/app.md +0 -77
  116. package/src/components/avatar/avatar.md +0 -64
  117. package/src/components/button/button.md +0 -66
  118. package/src/components/cable/cable.md +0 -57
  119. package/src/components/card/card/card.md +0 -57
  120. package/src/components/card/card-body/card-body.md +0 -34
  121. package/src/components/card/card-footer/card-footer.md +0 -42
  122. package/src/components/card/card-header/card-header.md +0 -44
  123. package/src/components/checkbox/checkbox.md +0 -60
  124. package/src/components/collapse/collapse.md +0 -59
  125. package/src/components/container/container.md +0 -38
  126. package/src/components/decision-modal/decision-modal.md +0 -79
  127. package/src/components/divider/divider.md +0 -42
  128. package/src/components/field/field.md +0 -68
  129. package/src/components/field/outline/outline-field.md +0 -44
  130. package/src/components/form-group/form-group.md +0 -41
  131. package/src/components/gesture-indicator/gesture-indicator.md +0 -42
  132. package/src/components/image/image.md +0 -41
  133. package/src/components/layout/cell/cell.html +0 -1
  134. package/src/components/layout/cell/cell.md +0 -47
  135. package/src/components/layout/cell/cell.scss +0 -54
  136. package/src/components/layout/cell/cell.type.ts +0 -19
  137. package/src/components/layout/cell/cell.vue +0 -35
  138. package/src/components/layout/cell/index.ts +0 -2
  139. package/src/components/layout/grid/grid.md +0 -50
  140. package/src/components/modal/modal.md +0 -65
  141. package/src/components/page/page.md +0 -39
  142. package/src/components/present/present.md +0 -60
  143. package/src/components/radio/radio/radio.md +0 -53
  144. package/src/components/radio/radio-group/radio-group.md +0 -62
  145. package/src/components/refresher/refresher.md +0 -53
  146. package/src/components/route/route-navigator/route-navigator.md +0 -50
  147. package/src/components/route/route-outlet/route-outlet.md +0 -30
  148. package/src/components/route/route-provider/route-provider.md +0 -46
  149. package/src/components/route/route-wrapper/route-wrapper.md +0 -45
  150. package/src/components/segmented-field/segmented-field.md +0 -58
  151. package/src/components/skeleton/skeleton.md +0 -47
  152. package/src/components/switch/switch.md +0 -57
  153. package/src/components/tabs/tab/tab.md +0 -52
  154. package/src/components/tabs/tabs/tabs.md +0 -59
  155. package/src/components/toast/toast/toast.md +0 -56
  156. package/src/components/toast/toast-content/toast-content.md +0 -41
  157. package/src/components/toolbar/toolbar.md +0 -54
@@ -3,7 +3,7 @@
3
3
  <script lang="ts" setup>
4
4
  import { computed, inject, nextTick, onMounted, onUnmounted, provide, ref, watch } from "vue";
5
5
  import { type TabsProps, type TabsEmit, type TabsProviderState } from "./tabs.type";
6
- import { property, withPrefix } from "../../../utils";
6
+ import { cssProperty, cssPrefix } from "../../../utils";
7
7
  import { type AppProviderState, APP_PROVIDER_STATE_KEY } from "../../app";
8
8
  import { TABS_PROVIDER_STATE_KEY } from "./tabs.constants";
9
9
 
@@ -12,9 +12,9 @@ import { TABS_PROVIDER_STATE_KEY } from "./tabs.constants";
12
12
  const props = withDefaults(defineProps<TabsProps>(), {
13
13
  placement: "top-start",
14
14
  margin: () => [0, 0],
15
- border: 2,
16
- divider: undefined,
15
+ border: () => [2, 0],
17
16
  transition: true,
17
+ size: "standard",
18
18
  });
19
19
  const emit = defineEmits<TabsEmit>();
20
20
  const appState = inject<AppProviderState>(APP_PROVIDER_STATE_KEY);
@@ -26,6 +26,7 @@ const height = ref(0);
26
26
  const top = ref(0);
27
27
  const left = ref(0);
28
28
  const container = ref();
29
+ const isFirstRender = ref(true);
29
30
 
30
31
  // Computed properties
31
32
  // ----------------------------------------------------------------------------
@@ -37,13 +38,15 @@ const shape = computed(() => {
37
38
  return props.shape || appState?.shape.value || "";
38
39
  });
39
40
 
41
+ const size = computed(() => {
42
+ return props.size;
43
+ });
44
+
40
45
  const activeValue = computed(() => {
41
46
  return props.modelValue || "";
42
47
  });
43
48
 
44
49
  const tabsAttrs = computed(() => {
45
- const divider =
46
- (props.divider !== undefined ? props.divider : appState?.divider.value || false) ?? false;
47
50
  let l = left.value;
48
51
  let t = top.value;
49
52
  let w = width.value;
@@ -57,7 +60,7 @@ const tabsAttrs = computed(() => {
57
60
  if (props.variant === "underline") {
58
61
  // Underline variant: align the highlight strip for top vs bottom tab bars
59
62
  if (props.placement.startsWith("top-")) {
60
- t = h - props.border;
63
+ t = h - props.border[0];
61
64
  }
62
65
 
63
66
  if (props.placement.startsWith("bottom-")) {
@@ -65,12 +68,17 @@ const tabsAttrs = computed(() => {
65
68
  }
66
69
 
67
70
  if (props.placement.startsWith("top-") || props.placement.startsWith("bottom-")) {
68
- h = props.border + 0.5;
71
+ h = props.border[0] + 0.5;
72
+
73
+ if (props.border[1]) {
74
+ l += (w - props.border[1]) / 2;
75
+ w = props.border[1];
76
+ }
69
77
  }
70
78
 
71
79
  // Left, Right
72
80
  if (props.placement.startsWith("left-")) {
73
- l = w - props.border;
81
+ l = w - props.border[0];
74
82
  }
75
83
 
76
84
  if (props.placement.startsWith("right-")) {
@@ -78,30 +86,34 @@ const tabsAttrs = computed(() => {
78
86
  }
79
87
 
80
88
  if (props.placement.startsWith("left-") || props.placement.startsWith("right-")) {
81
- w = props.border;
89
+ w = props.border[0];
90
+
91
+ if (props.border[1]) {
92
+ t += (h - props.border[1]) / 2;
93
+ h = props.border[1];
94
+ }
82
95
  }
83
96
  }
84
97
 
85
98
  return {
86
99
  class: [
87
- withPrefix(["layer", "tabs"]),
88
- withPrefix(["role", role.value]),
89
- withPrefix(["shape", shape.value]),
90
- withPrefix("tabs"),
100
+ cssPrefix(["layer", "tabs"]),
101
+ cssPrefix(["role", role.value]),
102
+ cssPrefix(["shape", shape.value]),
103
+ cssPrefix("tabs"),
91
104
  props.variant,
92
105
  props.placement,
93
106
  {
94
- divider,
95
- transition: props.transition,
107
+ transition: isFirstRender.value ? false : props.transition,
96
108
  },
97
109
  ],
98
110
  style: {
99
- [property("highlight-top")]: typeof t === "string" ? t : t + "px",
100
- [property("highlight-left")]: typeof l === "string" ? l : l + "px",
101
- [property("highlight-width")]: typeof w === "string" ? w : w + "px",
102
- [property("highlight-height")]: typeof h === "string" ? h : h + "px",
103
- [property("highlight-space-x")]: (props.margin[1] > 0 ? props.margin[1] : 0) + "px",
104
- [property("highlight-space-y")]: (props.margin[0] > 0 ? props.margin[0] : 0) + "px",
111
+ [cssProperty("tabs-highlight-top")]: typeof t === "string" ? t : t + "px",
112
+ [cssProperty("tabs-highlight-left")]: typeof l === "string" ? l : l + "px",
113
+ [cssProperty("tabs-highlight-width")]: typeof w === "string" ? w : w + "px",
114
+ [cssProperty("tabs-highlight-height")]: typeof h === "string" ? h : h + "px",
115
+ [cssProperty("tabs-highlight-space-x")]: (props.margin[1] > 0 ? props.margin[1] : 0) + "px",
116
+ [cssProperty("tabs-highlight-space-y")]: (props.margin[0] > 0 ? props.margin[0] : 0) + "px",
105
117
  },
106
118
  };
107
119
  });
@@ -124,20 +136,27 @@ const calcPosition = () => {
124
136
  }
125
137
  };
126
138
 
139
+ const checkRender = async () => {
140
+ await nextTick();
141
+ calcPosition();
142
+ };
143
+
127
144
  // Lifecycle
128
145
  // ----------------------------------------------------------------------------
129
146
  watch(
130
147
  () => props.modelValue,
131
- async () => {
132
- await nextTick();
133
- calcPosition();
148
+ () => {
149
+ checkRender();
134
150
  }
135
151
  );
136
152
 
137
- onMounted(async () => {
138
- await nextTick();
139
- calcPosition();
153
+ onMounted(() => {
154
+ checkRender();
140
155
  window.addEventListener("resize", calcPosition);
156
+
157
+ setTimeout(() => {
158
+ isFirstRender.value = false;
159
+ }, 500);
141
160
  });
142
161
 
143
162
  onUnmounted(() => {
@@ -150,6 +169,7 @@ provide<TabsProviderState>(TABS_PROVIDER_STATE_KEY, {
150
169
  activeValue,
151
170
  role,
152
171
  shape,
172
+ size,
153
173
  setValue: (val: unknown) => {
154
174
  emit("update:modelValue", val as string);
155
175
  },
@@ -3,7 +3,7 @@
3
3
  <script lang="ts" setup>
4
4
  import { computed } from "vue";
5
5
  import { type ToastProps } from "../toast.type";
6
- import { withPrefix } from "../../../utils";
6
+ import { cssPrefix } from "../../../utils";
7
7
  import { useToast } from "../toast.composable";
8
8
  import { ToastContent } from "../toast-content";
9
9
 
@@ -18,7 +18,7 @@ const toast = useToast();
18
18
  // ----------------------------------------------------------------------------
19
19
  const toastAttrs = computed(() => {
20
20
  return {
21
- class: [withPrefix("toast"), props.placement],
21
+ class: [cssPrefix("toast"), props.placement],
22
22
  };
23
23
  });
24
24
 
@@ -10,7 +10,8 @@ $toast-border-color: sass.fn-naming-var("toast", "border-color");
10
10
 
11
11
  $space-x: sass.fn-naming-var("spacing", "x");
12
12
  $transition-duration: sass.fn-naming-var("motion", "duration");
13
- $border-radius: sass.fn-naming-var("border-radius");
13
+ $radius-ratio: sass.fn-naming-var("radius-ratio");
14
+ $radius-size: sass.fn-naming-var("radius-size");
14
15
  $border-width: sass.fn-naming-var("stroke", "width");
15
16
  $max-height: sass.fn-naming-var("overlay", "max-height");
16
17
 
@@ -25,15 +26,15 @@ $max-height: sass.fn-naming-var("overlay", "max-height");
25
26
  border-radius #{$transition-duration} ease,
26
27
  opacity #{$transition-duration} ease;
27
28
 
28
- background-color: rgb(#{$toast-background-color});
29
- color: rgb(#{$toast-color});
30
- border-color: rgb(#{$toast-border-color});
29
+ background-color: rgba(#{$toast-background-color});
30
+ color: rgba(#{$toast-color});
31
+ border-color: rgba(#{$toast-border-color});
31
32
  border-width: #{$border-width};
32
33
  border-style: solid;
33
34
  max-height: #{$max-height};
34
35
  max-width: 100%;
35
36
  padding: calc(#{$space-x} * 2) calc(#{$space-x} * 4);
36
- border-radius: #{$border-radius};
37
+ border-radius: calc(min(#{$radius-size}, #{$max-height}) * #{$radius-ratio});
37
38
 
38
39
  &.closing {
39
40
  opacity: 0;
@@ -3,7 +3,7 @@
3
3
  <script lang="ts" setup>
4
4
  import { computed, inject, onMounted, ref } from "vue";
5
5
  import { type ToastContentProps, type ToastContentEmit } from "../toast.type";
6
- import { withPrefix } from "../../../utils";
6
+ import { cssPrefix } from "../../../utils";
7
7
  import { type AppProviderState, APP_PROVIDER_STATE_KEY } from "../../app";
8
8
 
9
9
  // Component setup (props, emits, injects)
@@ -27,10 +27,10 @@ const contentAttrs = computed(() => {
27
27
  const shape = props.shape || appState?.shape.value || "";
28
28
  return {
29
29
  class: [
30
- withPrefix(["layer", "toast"]),
31
- withPrefix(["role", role]),
32
- withPrefix(["shape", shape]),
33
- withPrefix("toast-content"),
30
+ cssPrefix(["layer", "toast"]),
31
+ cssPrefix(["role", role]),
32
+ cssPrefix(["shape", shape]),
33
+ cssPrefix("toast-content"),
34
34
  props.variant,
35
35
  {
36
36
  closing: isClosing.value,
@@ -14,11 +14,11 @@ $safe-area-top: sass.fn-naming-var("safe-area", "top");
14
14
  $transition-duration: sass.fn-naming-var("motion", "duration");
15
15
 
16
16
  $border-width: sass.fn-naming-var("stroke", "width");
17
- $border: #{$border-width} solid rgb(#{$toolbar-border-color});
17
+ $border: #{$border-width} solid rgba(#{$toolbar-border-color});
18
18
 
19
19
  .#{$toolbar} {
20
- background-color: rgb(#{$toolbar-background-color});
21
- color: rgb(#{$toolbar-color});
20
+ background-color: rgba(#{$toolbar-background-color});
21
+ color: rgba(#{$toolbar-color});
22
22
  transition:
23
23
  box-shadow #{$transition-duration} ease,
24
24
  border-color #{$transition-duration} ease,
@@ -26,7 +26,7 @@ $border: #{$border-width} solid rgb(#{$toolbar-border-color});
26
26
  color #{$transition-duration} ease,
27
27
  border-radius #{$transition-duration} ease;
28
28
 
29
- &.with-safe-area {
29
+ &.safe {
30
30
  &.right {
31
31
  padding-right: #{$safe-area-right};
32
32
  }
@@ -1,7 +1,7 @@
1
1
  // Type definitions
2
2
  export type ToolbarProps = {
3
3
  placement?: string | null;
4
- safeArea?: boolean;
4
+ safe?: boolean;
5
5
  role?: string;
6
6
  divider?: boolean;
7
7
  };
@@ -3,7 +3,7 @@
3
3
  <script lang="ts" setup>
4
4
  import { computed, inject } from "vue";
5
5
  import { type ToolbarProps } from "./toolbar.type";
6
- import { property, withPrefix } from "../../utils";
6
+ import { cssProperty, cssPrefix } from "../../utils";
7
7
  import { type CableProviderState } from "../cable/cable.type";
8
8
  import { type AppProviderState, APP_PROVIDER_STATE_KEY } from "../app";
9
9
  import { CABLE_PROVIDER_STATE_KEY } from "../cable";
@@ -12,7 +12,7 @@ import { CABLE_PROVIDER_STATE_KEY } from "../cable";
12
12
  // ----------------------------------------------------------------------------
13
13
  const props = withDefaults(defineProps<ToolbarProps>(), {
14
14
  placement: null,
15
- safeArea: true,
15
+ safe: true,
16
16
  divider: undefined,
17
17
  });
18
18
  const cable = inject<CableProviderState>(CABLE_PROVIDER_STATE_KEY);
@@ -27,13 +27,13 @@ const toolbarAttrs = computed(() => {
27
27
 
28
28
  return {
29
29
  class: [
30
- withPrefix(["layer", "toolbar"]),
31
- withPrefix(["role", role]),
32
- withPrefix("toolbar"),
30
+ cssPrefix(["layer", "toolbar"]),
31
+ cssPrefix(["role", role]),
32
+ cssPrefix("toolbar"),
33
33
  placement,
34
34
  {
35
- "with-safe-area": props.safeArea,
36
- divider: divider.value,
35
+ safe: props.safe,
36
+ divider: divider,
37
37
  },
38
38
  ],
39
39
  };
package/src/factory.ts CHANGED
@@ -16,10 +16,11 @@ import {
16
16
  Dropdown,
17
17
  Field,
18
18
  Flex,
19
+ FlexItem,
19
20
  FormGroup,
20
21
  GestureIndicator,
21
22
  Grid,
22
- Cell,
23
+ GridItem,
23
24
  Image,
24
25
  Modal,
25
26
  Page,
@@ -33,6 +34,7 @@ import {
33
34
  RouteOutlet,
34
35
  SegmentedField,
35
36
  Select,
37
+ SlideRange,
36
38
  Skeleton,
37
39
  Switch,
38
40
  Tab,
@@ -41,54 +43,110 @@ import {
41
43
  ToastContent,
42
44
  Toolbar,
43
45
  } from "./components";
44
- import { type CreateToifeOptions } from "./type";
45
- import type { App as VueApp } from "vue";
46
+ import { type SubscribeOptions } from "./type";
47
+ import { DefineComponent, ref, type App as VueApp } from "vue";
46
48
 
47
- export const createToife = (options?: CreateToifeOptions) => {
48
- return {
49
- install: (app: VueApp) => {
50
- const prefix = options?.prefix || "t-";
51
- app.component(prefix + "app", App);
52
- app.component(prefix + "action", Action);
53
- app.component(prefix + "avatar", Avatar);
54
- app.component(prefix + "button", Button);
55
- app.component(prefix + "cable", Cable);
56
- app.component(prefix + "card", Card);
57
- app.component(prefix + "card-body", CardBody);
58
- app.component(prefix + "card-header", CardHeader);
59
- app.component(prefix + "card-footer", CardFooter);
60
- app.component(prefix + "checkbox", Checkbox);
61
- app.component(prefix + "radio", Radio);
62
- app.component(prefix + "radio-group", RadioGroup);
63
- app.component(prefix + "collapse", Collapse);
64
- app.component(prefix + "container", Container);
65
- app.component(prefix + "decision-modal", DecisionModal);
66
- app.component(prefix + "divider", Divider);
67
- app.component(prefix + "dropdown", Dropdown);
68
- app.component(prefix + "field", Field);
69
- app.component(prefix + "flex", Flex);
70
- app.component(prefix + "form-group", FormGroup);
71
- app.component(prefix + "gesture-indicator", GestureIndicator);
72
- app.component(prefix + "grid", Grid);
73
- app.component(prefix + "cell", Cell);
74
- app.component(prefix + "image", Image);
75
- app.component(prefix + "modal", Modal);
76
- app.component(prefix + "page", Page);
77
- app.component(prefix + "present", Present);
78
- app.component(prefix + "refresher", Refresher);
79
- app.component(prefix + "route-navigator", RouteNavigator);
80
- app.component(prefix + "route-wrapper", RouteWrapper);
81
- app.component(prefix + "route-provider", RouteProvider);
82
- app.component(prefix + "route-outlet", RouteOutlet);
83
- app.component(prefix + "segmented-field", SegmentedField);
84
- app.component(prefix + "select", Select);
85
- app.component(prefix + "skeleton", Skeleton);
86
- app.component(prefix + "switch", Switch);
87
- app.component(prefix + "tab", Tab);
88
- app.component(prefix + "tabs", Tabs);
89
- app.component(prefix + "toast", Toast);
90
- app.component(prefix + "toast-content", ToastContent);
91
- app.component(prefix + "toolbar", Toolbar);
92
- },
93
- };
49
+ const apps = ref<Record<string, any>>({});
50
+ const defaultAppName = "toife";
51
+
52
+ class Toife {
53
+ /**
54
+ * Subscribe options
55
+ */
56
+ public options: SubscribeOptions;
57
+ public app: VueApp;
58
+
59
+ /**
60
+ * Constructor
61
+ */
62
+ constructor(app: VueApp, options?: SubscribeOptions) {
63
+ this.options = options || {
64
+ name: defaultAppName,
65
+ prefix: "t-",
66
+ };
67
+
68
+ this.app = app;
69
+ }
70
+
71
+ /**
72
+ * Subscribe components
73
+ */
74
+ subscribeComponents() {
75
+ const prefix = this.options.prefix;
76
+ this.app.component(prefix + "app", App);
77
+ this.app.component(prefix + "action", Action);
78
+ this.app.component(prefix + "avatar", Avatar);
79
+ this.app.component(prefix + "button", Button);
80
+ this.app.component(prefix + "cable", Cable);
81
+ this.app.component(prefix + "card", Card);
82
+ this.app.component(prefix + "card-body", CardBody);
83
+ this.app.component(prefix + "card-header", CardHeader);
84
+ this.app.component(prefix + "card-footer", CardFooter);
85
+ this.app.component(prefix + "checkbox", Checkbox);
86
+ this.app.component(prefix + "radio", Radio);
87
+ this.app.component(prefix + "radio-group", RadioGroup);
88
+ this.app.component(prefix + "collapse", Collapse);
89
+ this.app.component(prefix + "container", Container);
90
+ this.app.component(prefix + "decision-modal", DecisionModal);
91
+ this.app.component(prefix + "divider", Divider);
92
+ this.app.component(prefix + "dropdown", Dropdown);
93
+ this.app.component(prefix + "field", Field);
94
+ this.app.component(prefix + "flex", Flex);
95
+ this.app.component(prefix + "flex-item", FlexItem);
96
+ this.app.component(prefix + "form-group", FormGroup);
97
+ this.app.component(prefix + "gesture-indicator", GestureIndicator);
98
+ this.app.component(prefix + "grid", Grid);
99
+ this.app.component(prefix + "grid-item", GridItem);
100
+ this.app.component(prefix + "image", Image);
101
+ this.app.component(prefix + "modal", Modal);
102
+ this.app.component(prefix + "page", Page);
103
+ this.app.component(prefix + "present", Present);
104
+ this.app.component(prefix + "refresher", Refresher);
105
+ this.app.component(prefix + "route-navigator", RouteNavigator);
106
+ this.app.component(prefix + "route-wrapper", RouteWrapper);
107
+ this.app.component(prefix + "route-provider", RouteProvider);
108
+ this.app.component(prefix + "route-outlet", RouteOutlet);
109
+ this.app.component(prefix + "segmented-field", SegmentedField);
110
+ this.app.component(prefix + "select", Select);
111
+ this.app.component(prefix + "slide-range", SlideRange);
112
+ this.app.component(prefix + "skeleton", Skeleton);
113
+ this.app.component(prefix + "switch", Switch);
114
+ this.app.component(prefix + "tab", Tab);
115
+ this.app.component(prefix + "tabs", Tabs);
116
+ this.app.component(prefix + "toast", Toast);
117
+ this.app.component(prefix + "toast-content", ToastContent);
118
+ this.app.component(prefix + "toolbar", Toolbar);
119
+ }
120
+
121
+ /**
122
+ * Subscribe a component
123
+ */
124
+ subscribe(name: string, component: DefineComponent<{}, {}, any>) {
125
+ if (!this.app.component(this.options.prefix + name)) {
126
+ this.app.component(this.options.prefix + name, component);
127
+ }
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Subscribe components
133
+ */
134
+ export const createToife = (app: VueApp, options?: SubscribeOptions) => {
135
+ const instance = new Toife(app, options);
136
+ apps.value[instance.options.name] = instance;
137
+ return instance;
138
+ };
139
+
140
+ /**
141
+ * Get component name
142
+ */
143
+ export const useApp = (name: string = defaultAppName) => {
144
+ return apps.value[name] || null;
145
+ };
146
+
147
+ /**
148
+ * Get all apps
149
+ */
150
+ export const getApps = () => {
151
+ return apps.value;
94
152
  };
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  /// <reference path="./env.d.ts" />
2
2
  export * from "./factory";
3
- export * as utils from "./utils";
3
+ export * from "./utils";
4
4
  export * from "./components";
package/src/type.ts CHANGED
@@ -1,3 +1,4 @@
1
- export type CreateToifeOptions = {
1
+ export type SubscribeOptions = {
2
2
  prefix?: string;
3
+ name: string;
3
4
  };
@@ -4,7 +4,7 @@ let separator: string | null = null;
4
4
  /**
5
5
  * Get the separator from the document element
6
6
  */
7
- export const getSeparator = () => {
7
+ export const getCssSeparator = () => {
8
8
  if (!separator)
9
9
  separator = getComputedStyle(document.documentElement).getPropertyValue("--separator").trim();
10
10
 
@@ -14,7 +14,7 @@ export const getSeparator = () => {
14
14
  /**
15
15
  * Get the prefix from the document element
16
16
  */
17
- export const getPrefix = () => {
17
+ export const getCssPrefix = () => {
18
18
  if (!prefix)
19
19
  prefix = getComputedStyle(document.documentElement).getPropertyValue("--prefix").trim();
20
20
 
@@ -24,9 +24,9 @@ export const getPrefix = () => {
24
24
  /**
25
25
  * Generate the prefixed name
26
26
  */
27
- export const withPrefix = (name: string | string[]) => {
28
- const p = getPrefix();
29
- const s = getSeparator();
27
+ export const cssPrefix = (name: string | string[]) => {
28
+ const p = getCssPrefix();
29
+ const s = getCssSeparator();
30
30
  let names = [];
31
31
 
32
32
  if (typeof name === "string") {
@@ -45,13 +45,13 @@ export const withPrefix = (name: string | string[]) => {
45
45
  /**
46
46
  * Generate the property name
47
47
  */
48
- export const property = (name: string | string[]) => {
49
- return `--${withPrefix(name)}`;
48
+ export const cssProperty = (name: string | string[]) => {
49
+ return `--${cssPrefix(name)}`;
50
50
  };
51
51
 
52
52
  /**
53
53
  * Generate the name with var() syntax
54
54
  */
55
- export const variable = (name: string | string[]) => {
56
- return `var(${property(name)})`;
55
+ export const cssVariable = (name: string | string[]) => {
56
+ return `var(${cssProperty(name)})`;
57
57
  };
@@ -1,6 +1,6 @@
1
1
  # Utils: `style`
2
2
 
3
- > Import: `import { utils } from "@toife/vue"` then `utils.withPrefix`, … (or import from `src/utils` in the monorepo).
3
+ > Import: `import { utils } from "@toife/vue"` then `utils.cssPrefix`, … (or import from `src/utils` in the monorepo).
4
4
 
5
5
  **Source:** `src/utils/style/index.ts`
6
6
 
@@ -10,21 +10,21 @@ Reads `--prefix` and `--separator` from `document.documentElement` (cached), the
10
10
 
11
11
  ## API
12
12
 
13
- ### `getPrefix(): string`
13
+ ### `getCssPrefix(): string`
14
14
 
15
15
  Trimmed `--prefix` on `:root` (singleton cache).
16
16
 
17
- ### `getSeparator(): string`
17
+ ### `getCssSeparator(): string`
18
18
 
19
19
  Trimmed `--separator` (often `-` or `_`) used to join name parts.
20
20
 
21
- ### `withPrefix(name: string | string[]): string`
21
+ ### `cssPrefix(name: string | string[]): string`
22
22
 
23
23
  If prefix exists: `[prefix, ...parts].join(separator)`. `name` can be a string or parts array (e.g. `['layer','surface']`).
24
24
 
25
- ### `property(name: string | string[]): string`
25
+ ### `cssProperty(name: string | string[]): string`
26
26
 
27
- Returns the CSS custom property name **without** `var()`: `"--" + withPrefix(name)`.
27
+ Returns the CSS custom property name **without** `var()`: `"--" + cssPrefix(name)`.
28
28
 
29
29
  ### `variable(name: string | string[]): string`
30
30
 
@@ -35,8 +35,8 @@ Returns `var(--<prefixed…>)`.
35
35
  ```ts
36
36
  import { utils } from "@toife/vue";
37
37
 
38
- utils.withPrefix("button");
39
- utils.property(["field", "line"]);
38
+ utils.cssPrefix("button");
39
+ utils.cssProperty(["field", "line"]);
40
40
  utils.variable(["field", "line"]);
41
41
  ```
42
42
 
@@ -46,4 +46,4 @@ Requires `document` and `getComputedStyle` — client-only after `:root` defines
46
46
 
47
47
  ## See also
48
48
 
49
- - Components using `withPrefix` for BEM classes
49
+ - Components using `cssPrefix` for BEM classes