Skip to content

Commit 84eebd3

Browse files
feat: optional modal size params
1 parent e18a8d5 commit 84eebd3

File tree

9 files changed

+26
-16
lines changed

9 files changed

+26
-16
lines changed

packages/cli/templates/js/src/components.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ function ModalCloseButton() {
5555
},
5656
setup({ container, actions }) {
5757
container.querySelector('.btn-close').addEventListener('click', () => {
58-
actions.setModalOpen(!currentData.isModalOpen)
58+
actions.setModalOpen(!currentData.isModalOpen, {
59+
width: '50%',
60+
})
5961
})
6062
},
6163
update({ container, data }) {
@@ -114,7 +116,7 @@ function ModalToggle() {
114116
container
115117
.querySelector('.btn-modal-toggle')
116118
.addEventListener('click', () => {
117-
actions.setModalOpen(!currentData.isModalOpen)
119+
actions.setModalOpen(!currentData.isModalOpen, { width: '50%' })
118120
})
119121
},
120122
update({ container, data }) {

packages/cli/templates/react/src/components/FieldPluginExample/ModalToggle.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
import { FunctionComponent } from 'react'
2+
import type { SetModalOpen } from '@storyblok/field-plugin'
23

34
const ModalToggle: FunctionComponent<{
45
isModalOpen: boolean
5-
setModalOpen: (
6-
isModalOpen: boolean,
7-
modalSize?: { width: string; height: string },
8-
) => void
6+
setModalOpen: SetModalOpen<number>
97
}> = ({ isModalOpen, setModalOpen }) => {
108
return (
119
<div>
1210
<h2>Modal</h2>
1311
<button
1412
className="btn w-full"
1513
type="button"
16-
onClick={() => setModalOpen(!isModalOpen)}
14+
onClick={() => setModalOpen(!isModalOpen, { width: '50%' })}
1715
>
1816
{isModalOpen ? 'Close' : 'Open'} modal
1917
</button>

packages/cli/templates/vue2/src/components/FieldPluginExample/ModalToggle.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<button
55
class="btn w-full"
66
type="button"
7-
@click="() => setModalOpen(!isModalOpen)"
7+
@click="() => setModalOpen(!isModalOpen, { width: '50%' })"
88
>
99
{{ isModalOpen ? 'Close' : 'Open' }} modal
1010
</button>

packages/cli/templates/vue3/src/components/FieldPluginExample/ModalToggle.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ const props = defineProps<{
1313
<button
1414
class="btn w-full"
1515
type="button"
16-
@click="() => props.setModalOpen(!props.isModalOpen)"
16+
@click="
17+
() =>
18+
props.setModalOpen(!props.isModalOpen, {
19+
width: '50%',
20+
})
21+
"
1722
>
1823
{{ props.isModalOpen ? 'Close' : 'Open' }} modal
1924
</button>

packages/demo/src/components/ModalToggle.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ export const ModalToggle: PluginComponent = (props) => {
99
<Button
1010
variant="outlined"
1111
color="secondary"
12-
onClick={() => actions.setModalOpen(!data.isModalOpen)}
12+
onClick={() =>
13+
actions.setModalOpen(!data.isModalOpen, { width: '50%' })
14+
}
1315
>
1416
Toggle Modal
1517
</Button>

packages/field-plugin/src/createFieldPlugin/FieldPluginActions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ import { FieldPluginData } from './FieldPluginData'
44
export type SetContent<Content> = (
55
content: Content,
66
) => Promise<FieldPluginData<Content>>
7+
8+
export type ModalSize = { width?: string; height?: string }
9+
710
export type SetModalOpen<Content> = (
811
isModalOpen: boolean,
12+
modalSize?: ModalSize,
913
) => Promise<FieldPluginData<Content>>
1014
export type RequestContext = () => Promise<StoryData>
1115
export type SelectAsset = () => Promise<Asset>

packages/field-plugin/src/createFieldPlugin/FieldPluginData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export type FieldPluginData<Content> = {
99
options: Record<string, string>
1010
spaceId: number | undefined
1111
userId: number | undefined
12-
userPermissions: Record<string, any> | undefined
12+
userPermissions: Record<string, string[] | number[]> | undefined
1313
isSpaceAdmin: boolean
1414
interfaceLang: string
1515
storyLang: string

packages/field-plugin/src/createFieldPlugin/createPluginActions/createPluginActions.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,7 @@ export const createPluginActions: CreatePluginActions = ({
107107
)
108108
})
109109
},
110-
setModalOpen: (
111-
isModalOpen: boolean,
112-
modalSize?: { width: string; height: string },
113-
) => {
110+
setModalOpen: (isModalOpen, modalSize) => {
114111
return new Promise((resolve) => {
115112
const callbackId = pushCallback('stateChanged', (message) =>
116113
resolve(

packages/field-plugin/src/messaging/pluginMessage/pluginToContainerMessage/ModalChangeMessage.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { hasKey } from '../../../utils'
22
import { isMessageToContainer, MessageToContainer } from './MessageToContainer'
3+
import type { ModalSize } from 'packages/field-plugin/src/createFieldPlugin'
34

45
export type ModalChangeMessage = MessageToContainer<'toggleModal'> & {
56
status: boolean
6-
modalSize?: { width: string; height: string }
7+
modalSize?: ModalSize
78
}
9+
810
export const isModalChangeMessage = (obj: unknown): obj is ModalChangeMessage =>
911
isMessageToContainer(obj) &&
1012
obj.event === 'toggleModal' &&

0 commit comments

Comments
 (0)