Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit 18d5e74

Browse files
committed
refactor: improve build resolution for modules
1 parent 650b311 commit 18d5e74

10 files changed

+88
-86
lines changed

components.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* This is a generated file. Do not edit it's contents.
88
*
9-
* This file was generated on 2021-07-06T05:25:10.503Z
9+
* This file was generated on 2021-07-06T07:42:41.009Z
1010
*/
1111

1212
import { ChakraProps } from '@chakra-ui/vue-system'

packages/c-modal/examples/drawer-simple.vue

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
</template>
1111

1212
<script setup lang="ts">
13-
import { CDrawer } from '../src/c-drawer'
1413
import { useToggle } from '@vueuse/core'
1514
1615
const [isOpen, toggleOpen] = useToggle(false)

packages/c-modal/examples/drawer-with-much-content.vue

-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@
117117
</template>
118118

119119
<script setup lang="ts">
120-
import { CDrawer } from '../src/c-drawer'
121120
import { useToggle } from '@vueuse/core'
122121
123122
const [isOpen, toggleOpen] = useToggle(false)

packages/c-modal/src/c-alert-dialog.tsx

+20-23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ComponentWithProps, DeepPartial } from '@chakra-ui/vue-system'
2-
import { defineComponent, PropType, h, ref, watch } from 'vue'
2+
import { defineComponent, PropType, h, computed } from 'vue'
33
import {
44
CModal,
55
CModalContent,
@@ -23,37 +23,34 @@ export const CAlertDialog: ComponentWithProps<
2323
name: 'CAlertDialog',
2424
props: {
2525
...modalProps,
26-
leastDestructiveRef: [String, Object] as PropType<
26+
leastDestructiveRef: [Function, String] as PropType<
2727
CModalProps['initialFocusRef']
2828
>,
2929
},
3030
emits: ['update:modelValue', 'close', 'escape'],
3131
setup(props, { attrs, slots, emit }) {
32+
const isOpen = computed(() => props.modelValue!)
33+
3234
const handleUpdateModelValue = (val: boolean) => {
3335
emit('update:modelValue', val)
3436
}
35-
const closeDrawer = () => {
36-
emit('update:modelValue', false)
37-
}
38-
39-
const isOpen = ref(props.modelValue)
40-
41-
watch(isOpen, (newVal) => {
42-
emit('update:modelValue', newVal)
43-
})
4437

45-
return () => (
46-
<CModal
47-
{...props}
48-
{...attrs}
49-
label='alertdialog'
50-
v-model={isOpen.value}
51-
onClose={closeDrawer}
52-
initialFocusRef={props.leastDestructiveRef}
53-
>
54-
{slots}
55-
</CModal>
56-
)
38+
return () => {
39+
const { modelValue, "onUpdate:modelValue": updateModelValue, ...rest } = props
40+
return (
41+
<CModal
42+
{...rest}
43+
{...attrs}
44+
modelValue={isOpen.value}
45+
/* eslint-disable-next-line */
46+
onUpdate:modelValue={handleUpdateModelValue}
47+
label="alertdialog"
48+
initialFocusRef={props.leastDestructiveRef}
49+
>
50+
{slots}
51+
</CModal>
52+
)
53+
}
5754
},
5855
})
5956

packages/c-modal/src/c-drawer.tsx

+33-34
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
withDirectives,
99
watch,
1010
ref,
11+
Ref,
12+
watchEffect,
1113
} from 'vue'
1214
import {
1315
SlideDirection,
@@ -77,18 +79,11 @@ export const CDrawer: ComponentWithProps<
7779
},
7880
emits: ['update:modelValue', 'close', 'escape'],
7981
setup(props, { slots, attrs, emit }) {
82+
const isOpen = computed(() => props.modelValue!)
83+
8084
const handleUpdateModelValue = (val: boolean) => {
8185
emit('update:modelValue', val)
8286
}
83-
const closeDrawer = () => {
84-
emit('update:modelValue', false)
85-
}
86-
87-
const isOpen = ref(props.modelValue)
88-
89-
watch(isOpen, (newVal) => {
90-
emit('update:modelValue', newVal)
91-
})
9287

9388
const context: CDrawerContext = computed(() => ({
9489
placement: props.placement,
@@ -99,18 +94,23 @@ export const CDrawer: ComponentWithProps<
9994
const drawerStyleConfig = theme.components?.Drawer
10095

10196
CDrawerContextProvider(context)
102-
return () => (
103-
<CModal
104-
v-model={isOpen.value}
105-
onClose={closeDrawer}
106-
{...props}
107-
{...attrs}
108-
label='drawer'
109-
styleConfig={drawerStyleConfig}
110-
>
111-
{slots}
112-
</CModal>
113-
)
97+
98+
return () => {
99+
const { modelValue, "onUpdate:modelValue": updateModelValue, ...rest } = props
100+
return (
101+
<CModal
102+
{...rest}
103+
{...attrs}
104+
modelValue={isOpen.value}
105+
/* eslint-disable-next-line */
106+
onUpdate:modelValue={handleUpdateModelValue}
107+
label='drawer'
108+
styleConfig={drawerStyleConfig}
109+
>
110+
{slots}
111+
</CModal>
112+
)
113+
}
114114
},
115115
})
116116

@@ -166,7 +166,7 @@ export const CDrawerContent: ComponentWithProps<
166166
})
167167
}
168168

169-
watch(modelValue, (newVal) => {
169+
watch(modelValue!, (newVal) => {
170170
if (!newVal) {
171171
leave(() => null)
172172
}
@@ -183,32 +183,31 @@ export const CDrawerContent: ComponentWithProps<
183183

184184
const transitionVariant = computed(() => placementToVariant(placement!))
185185

186-
return () => (
187-
<chakra.div
188-
{...containerProps.value}
189-
__label="modal__content-container"
190-
__css={dialogContainerStyles.value}
191-
>
192-
{modelValue.value &&
193-
(() =>
186+
return () => {
187+
return <chakra.div
188+
{...containerProps.value}
189+
__label="modal__content-container"
190+
__css={dialogContainerStyles.value}
191+
>
192+
{modelValue!.value &&
194193
withDirectives(
195194
<chakra.section
196195
{...dialogProps.value}
197196
style={transitionStyles.value}
198197
__css={dialogStyles.value}
199198
{...attrs}
200199
>
201-
{() => slots?.default?.()}
200+
{slots}
202201
</chakra.section>,
203202
[
204203
[
205204
MotionDirective(TransitionVariants[transitionVariant.value]),
206205
transitionId.value,
207206
],
208207
]
209-
))}
210-
</chakra.div>
211-
)
208+
)}
209+
</chakra.div>
210+
}
212211
},
213212
})
214213

packages/c-modal/src/c-modal.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
withDirectives,
2525
Component,
2626
onErrorCaptured,
27+
Ref,
2728
} from 'vue'
2829
import {
2930
chakra,
@@ -70,7 +71,10 @@ export interface ModalOptions
7071
}
7172

7273
export interface CModalProps
73-
extends Omit<UnwrapRef<UseModalOptions>, 'closeModal' | 'handleEscape'>,
74+
extends Omit<
75+
UnwrapRef<UseModalOptions>,
76+
'closeModal' | 'handleEscape' | 'modelValue'
77+
>,
7478
Pick<CPortalProps, 'label'>,
7579
ModalOptions {
7680
/**
@@ -146,13 +150,15 @@ type IUseModalOptions = ToRefs<
146150
| 'allowPinchZoom'
147151
| 'trapFocus'
148152
| 'autoFocus'
153+
| 'modelValue'
149154
>
150155
>
151156

152157
interface CModalContext extends IUseModalOptions, UseModalReturn {
153158
dialogRef: (el: TemplateRef) => void
154159
overlayRef: (el: TemplateRef) => void
155160
closeModal: () => void
161+
modelValue: Ref<boolean>
156162
}
157163

158164
type CModalReactiveContext = ComputedRef<CModalContext>
@@ -310,7 +316,7 @@ export const CModalContent: ComponentWithProps<
310316
})
311317
}
312318

313-
watch(modelValue, (newVal) => {
319+
watch(modelValue!, (newVal) => {
314320
if (!newVal) {
315321
leave(() => null)
316322
}
@@ -343,7 +349,7 @@ export const CModalContent: ComponentWithProps<
343349
}),
344350
dialogContainerProps.value({ emit }),
345351
() => [
346-
modelValue.value &&
352+
modelValue!.value &&
347353
withDirectives(
348354
h(
349355
chakra('section', {

packages/c-modal/src/use-modal.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export function useModal(options: UseModalOptions) {
137137
initialFocus = resolvedInitialFocusRef?.$el || resolvedInitialFocusRef
138138
}
139139
}
140-
console.log({ initialFocus })
140+
141141
return initialFocus
142142
})
143143

packages/c-modal/tests/alertdialog.cy.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ describe('AlertDialog', () => {
9090

9191
/**
9292
* Why are we skipping this test for now?
93-
*
93+
*
9494
* There seems to be a bug in Cypress that was
9595
* introduced with the latest upgrade to Vue 3.0.11
9696
* with regards to forming focus traps.
97-
*
97+
*
9898
* The actual implementation in the browser works,
9999
* but this test fails for a reason that I am yet
100100
* to discover.
101-
*
101+
*
102102
* This should be treated as important however.
103103
*/
104104
it.skip('should trap focus while open', () => {

packages/c-modal/tests/modal.cy.tsx

+17-18
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ describe('Modal', () => {
8888

8989
/**
9090
* Why are we skipping this test for now?
91-
*
91+
*
9292
* There seems to be a bug in Cypress that was
9393
* introduced with the latest upgrade to Vue 3.0.11
9494
* with regards to forming focus traps.
95-
*
95+
*
9696
* The actual implementation in the browser works,
9797
* but this test fails for a reason that I am yet
9898
* to discover.
99-
*
99+
*
100100
* This should be treated as important however.
101101
*/
102102
it.skip('should set initial focus ref', () => {
@@ -128,21 +128,20 @@ describe('Modal', () => {
128128
)
129129
)
130130

131-
cy.get('[data-testid="initial-focus"]')
132-
.should('have.focus')
131+
cy.get('[data-testid="initial-focus"]').should('have.focus')
133132
})
134133

135134
/**
136135
* Why are we skipping this test for now?
137-
*
136+
*
138137
* There seems to be a bug in Cypress that was
139138
* introduced with the latest upgrade to Vue 3.0.11
140139
* with regards to forming focus traps.
141-
*
140+
*
142141
* The actual implementation in the browser works,
143142
* but this test fails for a reason that I am yet
144143
* to discover.
145-
*
144+
*
146145
* This should be treated as important however.
147146
*/
148147
it.skip('should trap focus while open', () => {
@@ -166,17 +165,17 @@ describe('Modal', () => {
166165
))
167166
)
168167

169-
cy
170-
.wait(1000)
171-
.get('[data-testid="close-button"]').should('have.focus')
168+
cy.wait(1000)
169+
.get('[data-testid="close-button"]')
170+
.should('have.focus')
172171
.log('Trigger tab() 20 times')
173-
new Array(20).forEach(() => {
174-
// @ts-expect-error Tab action
175-
cy.focused().tab()
176-
})
177-
cy.get('[data-testid="dialog"]').then((el) => {
178-
expect(el[0].contains(document.activeElement)).to.be.true
179-
})
172+
new Array(20).forEach(() => {
173+
// @ts-expect-error Tab action
174+
cy.focused().tab()
175+
})
176+
cy.get('[data-testid="dialog"]').then((el) => {
177+
expect(el[0].contains(document.activeElement)).to.be.true
178+
})
180179
})
181180

182181
it('should return focus on close', () => {

vite.config.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const resolver = {
2121
CModalBody: 'c-modal',
2222
CModalFooter: 'c-modal',
2323
CModalCloseButton: 'c-modal',
24+
CDrawer: 'c-modal',
2425
CDrawerOverlay: 'c-modal',
2526
CDrawerFocusScope: 'c-modal',
2627
CDrawerContent: 'c-modal',
@@ -116,7 +117,9 @@ export default defineConfig({
116117
importName: name,
117118
path: path.join(
118119
path.resolve(__dirname, './packages'),
119-
`${resolver[name] || kebabCase(name)}/src`
120+
!(process.env.NODE_ENV === 'production')
121+
? `${resolver[name] || kebabCase(name)}/src`
122+
: '@chakra-ui/vue-next'
120123
),
121124
}
122125
},

0 commit comments

Comments
 (0)