Skip to content

Commit e6dea65

Browse files
committed
Passing style to modal
1 parent 91f0d07 commit e6dea65

File tree

6 files changed

+19
-19
lines changed

6 files changed

+19
-19
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ There is also an SSR build with CSS file extracted. Take a look in /dist folder.
302302
| clickToClose | false | Boolean | true | If set to `false`, it will not be possible to close modal by clicking on the background |
303303
| transition| false | String | | Transition name |
304304
| overlayTransition| false | String | 'overlay-fade'| Transition name for the background overlay |
305-
| classes | false | [String, Array] | 'v--modal' | Classes that will be applied to the modal box, if not specified, the default `v--modal` class will be applied |
306-
| styles | false | String | "" | Style that will be applied to the modal box (currently only supports strings)|
305+
| classes | false | [String, Array] | 'v--modal' | Classes that will be applied to the modal box, if not specified, the default `v--modal` class will be applied |
306+
| styles | false | [String, Array, Object] | | Style that will be applied to the modal box (currently only supports strings)|
307307
| width | false | [String, Number] | 600 | Width in pixels or percents (e.g. 50 or "50px", "50%") |
308308
| height | false | [String, Number] | 300 | Height in pixels or percents (e.g. 50 or "50px", "50%") or `"auto"` |
309309
| minWidth | false | Number (px) | 0 | The minimum width to which modal can be resized |

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ssr.index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ssr.nocss.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Modal.vue

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ import {
5050
createModalEvent,
5151
getMutationObserver,
5252
blurActiveElement,
53-
windowWidthWithoutScrollbar
53+
windowWidthWithoutScrollbar,
54+
stringStylesToObject
5455
} from './utils'
5556
import { parseNumber, validateNumber } from './parser'
5657
@@ -346,19 +347,9 @@ export default {
346347
return ['v--modal-box', this.classes]
347348
},
348349
stylesProp () {
349-
if (typeof this.styles === 'string') {
350-
return this.styles
351-
.split(';')
352-
.map(v => v
353-
.trim()
354-
.split(':')
355-
)
356-
.reduce((styles, [key, value]) => {
357-
return { ...styles, [key]: value }
358-
})
359-
}
360-
361-
return this.styles
350+
return typeof this.styles === 'string'
351+
? stringStylesToObject(this.styles)
352+
: this.styles
362353
},
363354
/**
364355
* CSS styles for position and size of the modal

src/utils/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,12 @@ export const windowWidthWithoutScrollbar = () => {
6969

7070
return clientWidth || innerWidth
7171
}
72+
73+
export const stringStylesToObject = (styles) => {
74+
const lines = styles.split(';').map(line => line.trim()).filter(Boolean)
75+
const entries = lines.map(line => line.split(':'))
76+
77+
return entries.reduce((styles, [key, value]) => {
78+
return { ...styles, [key]: value }
79+
}, {})
80+
}

0 commit comments

Comments
 (0)