histoire 0.1.2 → 0.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 (47) hide show
  1. package/dist/client/app/App.vue +16 -1
  2. package/dist/client/app/components/app/AppHeader.vue +6 -6
  3. package/dist/client/app/components/app/Breadcrumb.vue +98 -0
  4. package/dist/client/app/components/app/MobileOverlay.vue +34 -0
  5. package/dist/client/app/components/misc/HatchedPattern.vue +11 -23
  6. package/dist/client/app/components/search/SearchItem.vue +1 -1
  7. package/dist/client/app/components/search/SearchModal.vue +2 -2
  8. package/dist/client/app/components/story/StoryListFolder.vue +2 -2
  9. package/dist/client/app/components/story/StoryListItem.vue +2 -2
  10. package/dist/client/app/components/story/StoryResponsivePreview.vue +94 -9
  11. package/dist/client/app/components/story/StorySidePanel.vue +68 -0
  12. package/dist/client/app/components/story/StoryVariantListItem.vue +2 -2
  13. package/dist/client/app/components/story/StoryVariantSingleView.vue +6 -2
  14. package/dist/client/app/components/story/StoryView.vue +10 -121
  15. package/dist/client/app/components/story/StoryViewer.vue +157 -0
  16. package/dist/client/app/stores/story.js +2 -1
  17. package/dist/client/app/stores/story.ts +6 -2
  18. package/dist/client/app/style/{floating-vue.css → floating-vue.pcss} +0 -0
  19. package/dist/client/app/style/{main.css → main.pcss} +13 -3
  20. package/dist/client/app/style/transitions.pcss +26 -0
  21. package/dist/client/app/util/responsive.d.ts +1 -0
  22. package/dist/client/app/util/responsive.js +2 -0
  23. package/dist/client/app/util/responsive.ts +3 -0
  24. package/dist/style.css +158 -67
  25. package/package.json +4 -4
  26. package/src/client/app/App.vue +16 -1
  27. package/src/client/app/components/app/AppHeader.vue +6 -6
  28. package/src/client/app/components/app/Breadcrumb.vue +98 -0
  29. package/src/client/app/components/app/MobileOverlay.vue +34 -0
  30. package/src/client/app/components/misc/HatchedPattern.vue +11 -23
  31. package/src/client/app/components/search/SearchItem.vue +1 -1
  32. package/src/client/app/components/search/SearchModal.vue +2 -2
  33. package/src/client/app/components/story/StoryListFolder.vue +2 -2
  34. package/src/client/app/components/story/StoryListItem.vue +2 -2
  35. package/src/client/app/components/story/StoryResponsivePreview.vue +94 -9
  36. package/src/client/app/components/story/StorySidePanel.vue +68 -0
  37. package/src/client/app/components/story/StoryVariantListItem.vue +2 -2
  38. package/src/client/app/components/story/StoryVariantSingleView.vue +6 -2
  39. package/src/client/app/components/story/StoryView.vue +10 -121
  40. package/src/client/app/components/story/StoryViewer.vue +157 -0
  41. package/src/client/app/stores/story.ts +6 -2
  42. package/src/client/app/style/{floating-vue.css → floating-vue.pcss} +0 -0
  43. package/src/client/app/style/{main.css → main.pcss} +13 -3
  44. package/src/client/app/style/transitions.pcss +26 -0
  45. package/src/client/app/util/responsive.ts +3 -0
  46. package/dist/client/app/style/transitions.css +0 -12
  47. package/src/client/app/style/transitions.css +0 -12
@@ -1,25 +1,13 @@
1
1
  <template>
2
- <svg fill="none">
3
- <pattern
4
- id="hatch"
5
- width="32"
6
- height="32"
7
- patternUnits="userSpaceOnUse"
8
- >
9
- <path
10
- d="M32,0 L0,32
11
- M-1,1 l2,-2
12
- M31,33 l2,-2"
13
- stroke-width="2"
14
- stroke="currentColor"
15
- />
16
- </pattern>
17
- <rect
18
- x="0"
19
- y="0"
20
- width="100%"
21
- height="100%"
22
- fill="url(#hatch)"
23
- />
24
- </svg>
2
+ <div class="__histoire-hatched-pattern" />
25
3
  </template>
4
+
5
+ <style scoped>
6
+ .__histoire-hatched-pattern {
7
+ background: repeating-linear-gradient(135deg,
8
+ transparent 0px,
9
+ transparent 32px,
10
+ currentColor 32px,
11
+ currentColor 64px);
12
+ }
13
+ </style>
@@ -57,7 +57,7 @@ const kindLabels = {
57
57
  >
58
58
  <Icon
59
59
  :icon="result.icon ?? defaultIcons[result.kind]"
60
- class="htw-w-5 htw-h-5"
60
+ class="htw-w-4 htw-h-4"
61
61
  :class="[
62
62
  !selected ? [
63
63
  result.iconColor
@@ -131,7 +131,7 @@ function selectPrevious () {
131
131
  <template>
132
132
  <div
133
133
  v-show="shown"
134
- class="htw-fixed htw-inset-0 htw-bg-white/80 dark:htw-bg-gray-700/80"
134
+ class="htw-fixed htw-inset-0 htw-bg-white/80 dark:htw-bg-gray-700/80 htw-z-20"
135
135
  >
136
136
  <div
137
137
  class="htw-absolute htw-inset-0"
@@ -144,7 +144,7 @@ function selectPrevious () {
144
144
  >
145
145
  <Icon
146
146
  icon="carbon:search"
147
- class="flex-none htw-w-5 htw-h-5"
147
+ class="flex-none htw-w-4 htw-h-4"
148
148
  />
149
149
 
150
150
  <input
@@ -34,7 +34,7 @@ const folderPadding = computed(() => {
34
34
  <div
35
35
  role="button"
36
36
  tabindex="0"
37
- class="htw-px-0.5 htw-py-1.5 htw-m-1 htw-rounded-sm hover:htw-bg-primary-100 dark:hover:htw-bg-primary-900 htw-cursor-pointer htw-select-none htw-flex"
37
+ class="htw-px-0.5 htw-py-2 md:htw-py-1.5 htw-m-1 htw-rounded-sm hover:htw-bg-primary-100 dark:hover:htw-bg-primary-900 htw-cursor-pointer htw-select-none htw-flex"
38
38
  @click="toggleOpen"
39
39
  @keyup.enter="toggleOpen"
40
40
  @keyup.space="toggleOpen"
@@ -50,7 +50,7 @@ const folderPadding = computed(() => {
50
50
  />
51
51
  <Icon
52
52
  icon="carbon:folder"
53
- class="htw-w-5 htw-h-5"
53
+ class="htw-w-5 htw-h-5 sm:htw-w-4 sm:htw-h-4"
54
54
  />
55
55
  </span>
56
56
  <span class="htw-truncate">{{ folder.title }}</span>
@@ -33,12 +33,12 @@ useScrollOnActive(active, el)
33
33
  storyId: story.id,
34
34
  },
35
35
  }"
36
- class="htw-pl-0.5 htw-pr-2 htw-py-1.5 htw-m-1 htw-rounded-sm"
36
+ class="htw-pl-0.5 htw-pr-2 htw-py-2 md:htw-py-1.5 htw-m-1 htw-rounded-sm"
37
37
  >
38
38
  <span class="bind-tree-margin htw-flex htw-items-center htw-gap-2 htw-pl-5 htw-min-w-0">
39
39
  <Icon
40
40
  :icon="story.icon ?? 'carbon:cube'"
41
- class="base-list-item-link-icon htw-w-5 htw-h-5 htw-flex-none"
41
+ class="base-list-item-link-icon htw-w-5 htw-h-5 sm:htw-w-4 sm:htw-h-4 htw-flex-none"
42
42
  :class="{
43
43
  'htw-text-primary-500': !active && !story.iconColor,
44
44
  'bind-icon-color': !active && story.iconColor,
@@ -1,5 +1,5 @@
1
1
  <script lang="ts" setup>
2
- import { computed, Ref, ref, toRaw, toRefs, watch } from 'vue'
2
+ import { computed, onUnmounted, Ref, ref, toRaw, watch } from 'vue'
3
3
  import { useEventListener } from '@vueuse/core'
4
4
  import { Icon } from '@iconify/vue'
5
5
  import { STATE_SYNC, PREVIEW_SETTINGS_SYNC, SANDBOX_READY } from '../../util/const'
@@ -8,6 +8,7 @@ import type { Story, Variant } from '../../types'
8
8
  import HatchedPattern from '../misc/HatchedPattern.vue'
9
9
  import CheckerboardPattern from '../misc/CheckerboardPattern.vue'
10
10
  import { toRawDeep } from '../../util/reactivity'
11
+ import { Settings } from 'http2'
11
12
 
12
13
  const props = defineProps<{
13
14
  story: Story
@@ -15,6 +16,10 @@ const props = defineProps<{
15
16
  settings: PreviewSettings
16
17
  }>()
17
18
 
19
+ const emit = defineEmits({
20
+ 'update:settings': (settings: PreviewSettings) => true,
21
+ })
22
+
18
23
  // Iframe
19
24
 
20
25
  const iframe = ref<HTMLIFrameElement>()
@@ -98,29 +103,109 @@ function onIframeLoad () {
98
103
 
99
104
  const resizing = ref(false)
100
105
 
106
+ const onUnmountedCleanupFns: (() => unknown)[] = []
107
+ onUnmounted(() => {
108
+ onUnmountedCleanupFns.forEach(fn => fn())
109
+ })
110
+
111
+ function addWindowListener (event: string, listener: (event: any) => unknown) {
112
+ window.addEventListener(event, listener)
113
+ const removeListener = () => window.removeEventListener(event, listener)
114
+ onUnmountedCleanupFns.push(removeListener)
115
+ return () => {
116
+ removeListener()
117
+ onUnmountedCleanupFns.splice(onUnmountedCleanupFns.indexOf(removeListener), 1)
118
+ }
119
+ }
120
+
101
121
  function useDragger (el: Ref<HTMLDivElement>, value: Ref<number>, min: number, max: number, axis: 'x' | 'y') {
102
- const onMouseDown = (event: MouseEvent) => {
122
+ function onMouseDown (event: MouseEvent) {
103
123
  event.preventDefault()
104
124
  event.stopPropagation()
105
125
  const start = axis === 'x' ? event.clientX : event.clientY
106
126
  const startValue = value.value || (axis === 'x' ? iframe.value.offsetWidth : iframe.value.offsetHeight)
107
127
  resizing.value = true
108
- const onMouseMove = (event: MouseEvent) => {
128
+
129
+ const removeListeners = [
130
+ addWindowListener('mousemove', onMouseMove),
131
+ addWindowListener('mouseup', onMouseUp),
132
+ ]
133
+
134
+ function onMouseMove (event: MouseEvent) {
109
135
  const delta = (axis === 'x' ? event.clientX : event.clientY) - start
110
136
  value.value = Math.max(min, Math.min(max, startValue + delta))
111
137
  }
112
- const onMouseUp = () => {
113
- window.removeEventListener('mousemove', onMouseMove)
114
- window.removeEventListener('mouseup', onMouseUp)
138
+
139
+ function onMouseUp () {
140
+ removeListeners.forEach(fn => fn())
115
141
  resizing.value = false
116
142
  }
117
- window.addEventListener('mousemove', onMouseMove)
118
- window.addEventListener('mouseup', onMouseUp)
119
143
  }
120
144
  useEventListener(el, 'mousedown', onMouseDown)
145
+
146
+ function onTouchStart (event: TouchEvent) {
147
+ event.preventDefault()
148
+ event.stopPropagation()
149
+ const start = axis === 'x' ? event.touches[0].clientX : event.touches[0].clientY
150
+ const startValue = value.value || (axis === 'x' ? iframe.value.offsetWidth : iframe.value.offsetHeight)
151
+ resizing.value = true
152
+
153
+ const removeListeners = [
154
+ addWindowListener('touchmove', onTouchMove),
155
+ addWindowListener('touchend', onTouchEnd),
156
+ addWindowListener('touchcancel', onTouchEnd),
157
+ ]
158
+
159
+ function onTouchMove (event: TouchEvent) {
160
+ const delta = (axis === 'x' ? event.touches[0].clientX : event.touches[0].clientY) - start
161
+ value.value = Math.max(min, Math.min(max, startValue + delta))
162
+ }
163
+
164
+ function onTouchEnd () {
165
+ removeListeners.forEach(fn => fn())
166
+ resizing.value = false
167
+ }
168
+ }
169
+ useEventListener(el, 'touchstart', onTouchStart)
170
+ }
171
+
172
+ // Optimize by batching settings updates to the next frame
173
+ // Prevents sync issues with `useStorage`
174
+ let settingsUpdate: Partial<Settings> = {}
175
+ let settingsUpdateQueued = false
176
+
177
+ function updateSettings (settings: Partial<PreviewSettings>) {
178
+ Object.assign(settingsUpdate, settings)
179
+
180
+ if (!settingsUpdateQueued) {
181
+ settingsUpdateQueued = true
182
+ requestAnimationFrame(() => {
183
+ emit('update:settings', {
184
+ ...props.settings,
185
+ ...settingsUpdate,
186
+ })
187
+ settingsUpdate = {}
188
+ settingsUpdateQueued = false
189
+ })
190
+ }
121
191
  }
122
192
 
123
- const { responsiveWidth, responsiveHeight } = toRefs(props.settings)
193
+ const responsiveWidth = computed({
194
+ get: () => props.settings[props.settings.rotate ? 'responsiveHeight' : 'responsiveWidth'],
195
+ set: (value) => {
196
+ updateSettings({
197
+ [props.settings.rotate ? 'responsiveHeight' : 'responsiveWidth']: value,
198
+ })
199
+ },
200
+ })
201
+ const responsiveHeight = computed({
202
+ get: () => props.settings[props.settings.rotate ? 'responsiveWidth' : 'responsiveHeight'],
203
+ set: (value) => {
204
+ updateSettings({
205
+ [props.settings.rotate ? 'responsiveWidth' : 'responsiveHeight']: value,
206
+ })
207
+ },
208
+ })
124
209
 
125
210
  const horizontalDragger = ref<HTMLDivElement>()
126
211
  const verticalDragger = ref<HTMLDivElement>()
@@ -0,0 +1,68 @@
1
+ <script lang="ts" setup>
2
+ import { useRoute, useRouter } from 'vue-router'
3
+ import { useStoryStore } from '../../stores/story'
4
+
5
+ import BaseSplitPane from '../base/BaseSplitPane.vue'
6
+ import BaseEmpty from '../base/BaseEmpty.vue'
7
+ import BaseTab from '../base/BaseTab.vue'
8
+ import StoryControls from './StoryControls.vue'
9
+ import StoryDocs from './StoryDocs.vue'
10
+ import StorySourceCode from './StorySourceCode.vue'
11
+
12
+ const storyStore = useStoryStore()
13
+
14
+ const router = useRouter()
15
+ const route = useRoute()
16
+ </script>
17
+
18
+ <template>
19
+ <BaseEmpty v-if="!storyStore.currentVariant">
20
+ <span>Select a variant</span>
21
+ </BaseEmpty>
22
+
23
+ <BaseEmpty v-else-if="!storyStore.currentVariant.ready">
24
+ <span>Loading...</span>
25
+ </BaseEmpty>
26
+
27
+ <BaseSplitPane
28
+ v-else
29
+ save-id="story-sidepane"
30
+ orientation="portrait"
31
+ class="htw-h-full"
32
+ >
33
+ <template #first>
34
+ <div class="htw-flex htw-flex-col htw-h-full">
35
+ <nav class="htw-h-10 htw-flex-none htw-border-b htw-border-gray-100 dark:htw-border-gray-750">
36
+ <BaseTab
37
+ :to="{ ...$route, query: { ...$route.query, tab: '' } }"
38
+ :matched="!$route.query.tab"
39
+ >
40
+ Controls
41
+ </BaseTab>
42
+ <BaseTab
43
+ :to="{ ...$route, query: { ...$route.query, tab: 'docs' } }"
44
+ :matched="$route.query.tab === 'docs'"
45
+ >
46
+ Docs
47
+ </BaseTab>
48
+ </nav>
49
+
50
+ <component
51
+ :is="$route.query.tab === 'docs'
52
+ ? StoryDocs
53
+ : StoryControls"
54
+ :story="storyStore.currentStory"
55
+ :variant="storyStore.currentVariant"
56
+ class="htw-h-full htw-overflow-auto"
57
+ />
58
+ </div>
59
+ </template>
60
+
61
+ <template #last>
62
+ <StorySourceCode
63
+ :variant="storyStore.currentVariant"
64
+ class="htw-h-full"
65
+ />
66
+ </template>
67
+ </BaseSplitPane>
68
+ </template>
@@ -25,11 +25,11 @@ useScrollOnActive(isActive, el)
25
25
  v-slot="{ active }"
26
26
  :to="targetRoute"
27
27
  :is-active="isActive"
28
- class="htw-px-2 htw-py-1.5 htw-m-1 htw-rounded-sm htw-flex htw-items-center htw-gap-2"
28
+ class="htw-px-2 htw-py-2 md:htw-py-1.5 htw-m-1 htw-rounded-sm htw-flex htw-items-center htw-gap-2"
29
29
  >
30
30
  <Icon
31
31
  :icon="variant.icon ?? 'carbon:cube'"
32
- class="base-list-item-link-icon htw-w-5 htw-h-5 htw-flex-none"
32
+ class="base-list-item-link-icon htw-w-5 htw-h-5 sm:htw-w-4 sm:htw-h-4 htw-flex-none"
33
33
  :class="{
34
34
  'htw-text-gray-500': !active && !variant.iconColor,
35
35
  'bind-icon-color': !active && variant.iconColor,
@@ -5,6 +5,7 @@ import type { Story, Variant } from '../../types'
5
5
  import { histoireConfig } from '../../util/config'
6
6
  import { usePreviewSettings } from '../../util/preview-settings'
7
7
  import StoryResponsivePreview from './StoryResponsivePreview.vue'
8
+ import { isMobile } from '../../util/responsive'
8
9
 
9
10
  defineProps({
10
11
  variant: {
@@ -24,7 +25,10 @@ const settings = usePreviewSettings()
24
25
  <template>
25
26
  <div class="htw-h-full htw-flex htw-flex-col">
26
27
  <!-- Toolbar -->
27
- <div class="htw-flex-none htw-flex htw-items-center htw-h-8 -htw-mt-1">
28
+ <div
29
+ v-if="!isMobile"
30
+ class="htw-flex-none htw-flex htw-items-center htw-h-8 -htw-mt-1"
31
+ >
28
32
  <!-- Variant title -->
29
33
  <div class="htw-flex htw-items-center htw-gap-1 htw-text-gray-500 htw-flex-1 htw-truncate htw-min-w-0">
30
34
  <Icon
@@ -168,9 +172,9 @@ const settings = usePreviewSettings()
168
172
 
169
173
  <!-- Preview -->
170
174
  <StoryResponsivePreview
175
+ v-model:settings="settings"
171
176
  :story="story"
172
177
  :variant="variant"
173
- :settings="settings"
174
178
  />
175
179
  </div>
176
180
  </template>
@@ -1,27 +1,19 @@
1
1
  <script lang="ts" setup>
2
- import { computed, watch } from 'vue'
2
+ import { watch } from 'vue'
3
3
  import { useRoute, useRouter } from 'vue-router'
4
4
  import { useStoryStore } from '../../stores/story'
5
5
 
6
6
  import BaseSplitPane from '../base/BaseSplitPane.vue'
7
7
  import BaseEmpty from '../base/BaseEmpty.vue'
8
- import BaseTab from '../base/BaseTab.vue'
9
- import StoryVariantListItem from './StoryVariantListItem.vue'
10
- import StoryVariantGridItem from './StoryVariantGridItem.vue'
11
- import StoryVariantSingleView from './StoryVariantSingleView.vue'
12
- import StoryControls from './StoryControls.vue'
13
- import StoryDocs from './StoryDocs.vue'
14
- import StorySourceCode from './StorySourceCode.vue'
8
+ import { isMobile } from '../../util/responsive'
9
+ import StoryViewer from './StoryViewer.vue'
10
+ import StorySidePanel from './StorySidePanel.vue'
15
11
 
16
12
  const storyStore = useStoryStore()
17
13
 
18
14
  const router = useRouter()
19
15
  const route = useRoute()
20
16
 
21
- // Selected variant
22
-
23
- const hasSingleVariant = computed(() => (storyStore.currentStory?.variants.length === 1))
24
-
25
17
  // Restore variant selection
26
18
 
27
19
  watch(() => storyStore.currentVariant, value => {
@@ -67,7 +59,11 @@ function setVariant (variantId: string) {
67
59
  v-else
68
60
  class="htw-h-full"
69
61
  >
62
+ <template v-if="isMobile">
63
+ <StoryViewer />
64
+ </template>
70
65
  <BaseSplitPane
66
+ v-else
71
67
  save-id="story-main"
72
68
  :min="30"
73
69
  :max="95"
@@ -75,118 +71,11 @@ function setVariant (variantId: string) {
75
71
  class="htw-h-full"
76
72
  >
77
73
  <template #first>
78
- <div class="htw-bg-gray-50 htw-h-full dark:htw-bg-gray-750">
79
- <div
80
- v-if="storyStore.currentStory.layout.type === 'grid'"
81
- class="htw-h-full htw-overflow-y-auto"
82
- >
83
- <div
84
- class="htw-grid htw-gap-4 htw-m-4"
85
- :style="{
86
- gridTemplateColumns: `repeat(auto-fill, ${storyStore.currentStory.layout.width ?? 200}px)`,
87
- }"
88
- >
89
- <StoryVariantGridItem
90
- v-for="(variant, index) of storyStore.currentStory.variants"
91
- :key="index"
92
- :variant="variant"
93
- :story="storyStore.currentStory"
94
- />
95
- </div>
96
- </div>
97
-
98
- <template v-else-if="storyStore.currentStory.layout.type === 'single'">
99
- <div
100
- v-if="hasSingleVariant && storyStore.currentVariant"
101
- class="htw-p-2 htw-h-full"
102
- >
103
- <StoryVariantSingleView
104
- :variant="storyStore.currentVariant"
105
- :story="storyStore.currentStory"
106
- />
107
- </div>
108
- <BaseSplitPane
109
- v-else
110
- save-id="story-single-main-split"
111
- :min="5"
112
- :max="40"
113
- :default-split="17"
114
- >
115
- <template #first>
116
- <div class="htw-h-full htw-overflow-y-auto">
117
- <StoryVariantListItem
118
- v-for="(variant, index) of storyStore.currentStory.variants"
119
- :key="index"
120
- :variant="variant"
121
- />
122
- </div>
123
- </template>
124
- <template #last>
125
- <div
126
- v-if="storyStore.currentVariant"
127
- class="htw-p-2 htw-h-full"
128
- >
129
- <StoryVariantSingleView
130
- :variant="storyStore.currentVariant"
131
- :story="storyStore.currentStory"
132
- />
133
- </div>
134
- </template>
135
- </BaseSplitPane>
136
- </template>
137
- </div>
74
+ <StoryViewer />
138
75
  </template>
139
76
 
140
77
  <template #last>
141
- <BaseEmpty v-if="!storyStore.currentVariant">
142
- <span>Select a variant</span>
143
- </BaseEmpty>
144
-
145
- <BaseEmpty v-else-if="!storyStore.currentVariant.ready">
146
- <span>Loading...</span>
147
- </BaseEmpty>
148
-
149
- <BaseSplitPane
150
- v-else
151
- save-id="story-sidepane"
152
- orientation="portrait"
153
- class="htw-h-full"
154
- >
155
- <template #first>
156
- <div class="htw-flex htw-flex-col htw-h-full">
157
- <nav class="htw-h-10 htw-flex-none htw-border-b htw-border-gray-100 dark:htw-border-gray-750">
158
- <BaseTab
159
- :to="{ ...$route, query: { ...$route.query, tab: '' } }"
160
- :matched="!$route.query.tab"
161
- >
162
- Controls
163
- </BaseTab>
164
- <BaseTab
165
- :to="{ ...$route, query: { ...$route.query, tab: 'docs' } }"
166
- :matched="$route.query.tab === 'docs'"
167
- >
168
- Docs
169
- </BaseTab>
170
- </nav>
171
-
172
- <component
173
- :is="$route.query.tab === 'docs'
174
- ? StoryDocs
175
- : StoryControls"
176
- :story="storyStore.currentStory"
177
- :variant="storyStore.currentVariant"
178
- class="htw-h-full htw-overflow-auto"
179
- />
180
- </div>
181
- </template>
182
-
183
- <template #last>
184
- <StorySourceCode
185
- :variant="storyStore.currentVariant"
186
- class="htw-h-full"
187
- />
188
- </template>
189
- </BaseSplitPane>
78
+ <StorySidePanel />
190
79
  </template>
191
80
  </BaseSplitPane>
192
81
  </div>
@@ -0,0 +1,157 @@
1
+ <script lang="ts" setup>
2
+ import { computed, ref, watch } from 'vue'
3
+ import { useRoute, useRouter } from 'vue-router'
4
+ import { useStoryStore } from '../../stores/story'
5
+
6
+ import BaseSplitPane from '../base/BaseSplitPane.vue'
7
+ import StoryVariantListItem from './StoryVariantListItem.vue'
8
+ import StoryVariantGridItem from './StoryVariantGridItem.vue'
9
+ import StoryVariantSingleView from './StoryVariantSingleView.vue'
10
+ import { isMobile } from '../../util/responsive'
11
+ import { Icon } from '@iconify/vue'
12
+ import MobileOverlay from '../app/MobileOverlay.vue'
13
+
14
+ const storyStore = useStoryStore()
15
+
16
+ const router = useRouter()
17
+ const route = useRoute()
18
+
19
+ const hasSingleVariant = computed(() => (storyStore.currentStory?.variants.length === 1))
20
+
21
+ const variant = computed(() => storyStore.currentVariant)
22
+
23
+ const isMenuOpened = ref(false)
24
+
25
+ function openMenu () {
26
+ isMenuOpened.value = true
27
+ }
28
+
29
+ function closeMenu () {
30
+ isMenuOpened.value = false
31
+ }
32
+
33
+ watch(variant, () => {
34
+ isMenuOpened.value = false
35
+ })
36
+ </script>
37
+
38
+ <template>
39
+ <div class="htw-bg-gray-50 htw-h-full dark:htw-bg-gray-750">
40
+ <div
41
+ v-if="storyStore.currentStory.layout.type === 'grid'"
42
+ class="htw-h-full htw-overflow-y-auto"
43
+ >
44
+ <div
45
+ class="htw-grid htw-gap-4 htw-m-4"
46
+ :style="{
47
+ gridTemplateColumns: `repeat(auto-fill, ${storyStore.currentStory.layout.width ?? 200}px)`,
48
+ }"
49
+ >
50
+ <StoryVariantGridItem
51
+ v-for="(variant, index) of storyStore.currentStory.variants"
52
+ :key="index"
53
+ :variant="variant"
54
+ :story="storyStore.currentStory"
55
+ />
56
+ </div>
57
+ </div>
58
+
59
+ <template v-else-if="storyStore.currentStory.layout.type === 'single'">
60
+ <div
61
+ v-if="hasSingleVariant && storyStore.currentVariant"
62
+ class="htw-p-2 htw-h-full"
63
+ >
64
+ <StoryVariantSingleView
65
+ :variant="storyStore.currentVariant"
66
+ :story="storyStore.currentStory"
67
+ />
68
+ </div>
69
+ <template v-else>
70
+ <div
71
+ v-if="isMobile"
72
+ class="htw-divide-y htw-divide-gray-100 dark:htw-divide-gray-800 htw-h-full htw-flex htw-flex-col"
73
+ >
74
+ <a
75
+ class="htw-px-6 htw-h-12 hover:htw-text-primary-500 dark:hover:htw-text-primary-400 htw-cursor-pointer htw-flex htw-gap-2 htw-flex-wrap htw-w-full htw-items-center"
76
+ @click="openMenu"
77
+ >
78
+ <template v-if="variant">
79
+ <Icon
80
+ :icon="variant.icon ?? 'carbon:cube'"
81
+ class="base-list-item-link-icon htw-w-5 htw-h-5 htw-flex-none"
82
+ :class="{
83
+ 'htw-text-gray-500': !variant.iconColor,
84
+ 'bind-icon-color': variant.iconColor,
85
+ }"
86
+ />
87
+ {{ variant.title }}
88
+ </template>
89
+ <template v-else>
90
+ Select a variant...
91
+ </template>
92
+
93
+ <Icon
94
+ icon="carbon:chevron-sort"
95
+ class="htw-w-5 htw-h-5 htw-shrink-0 htw-ml-auto"
96
+ />
97
+ </a>
98
+ <div
99
+ v-if="storyStore.currentVariant"
100
+ class="htw-p-2 htw-h-full"
101
+ >
102
+ <StoryVariantSingleView
103
+ :variant="storyStore.currentVariant"
104
+ :story="storyStore.currentStory"
105
+ />
106
+ </div>
107
+ </div>
108
+ <BaseSplitPane
109
+ v-else
110
+ save-id="story-single-main-split"
111
+ :min="5"
112
+ :max="40"
113
+ :default-split="17"
114
+ >
115
+ <template #first>
116
+ <div class="htw-h-full htw-overflow-y-auto">
117
+ <StoryVariantListItem
118
+ v-for="(variant, index) of storyStore.currentStory.variants"
119
+ :key="index"
120
+ :variant="variant"
121
+ />
122
+ </div>
123
+ </template>
124
+ <template #last>
125
+ <div
126
+ v-if="storyStore.currentVariant"
127
+ class="htw-p-2 htw-h-full"
128
+ >
129
+ <StoryVariantSingleView
130
+ :variant="storyStore.currentVariant"
131
+ :story="storyStore.currentStory"
132
+ />
133
+ </div>
134
+ </template>
135
+ </BaseSplitPane>
136
+ </template>
137
+ </template>
138
+ </div>
139
+
140
+ <MobileOverlay
141
+ title="Select a variant"
142
+ :opened="isMenuOpened"
143
+ @close="closeMenu"
144
+ >
145
+ <StoryVariantListItem
146
+ v-for="(variant, index) of storyStore.currentStory.variants"
147
+ :key="index"
148
+ :variant="variant"
149
+ />
150
+ </MobileOverlay>
151
+ </template>
152
+
153
+ <style scoped>
154
+ .bind-icon-color {
155
+ color: v-bind('variant?.iconColor');
156
+ }
157
+ </style>