Skip to content

Commit 899779f

Browse files
authored
fix(icons): make icon transform props work with IE11 (closes bootstrap-vue#4607) (bootstrap-vue#4608)
1 parent defbec0 commit 899779f

File tree

3 files changed

+318
-22
lines changed

3 files changed

+318
-22
lines changed

src/icons/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ Vue.use(BootstrapVueIcons)
120120
```
121121

122122
BootstrapVue icons SCSS/CSS does not depend on any Bootstrap SASS variables, mixins, functions or
123-
CSS classes (other than the Bootstrap `text-{variant}` variant utility classes, if using the
123+
CSS classes (other than the Bootstrap `text-{variant}` text color utility classes, if using the
124124
`variant` prop). Please note that the icons CSS is _also_ included in the main BootstrapVue SCSS/CSS
125125
files.
126126

@@ -299,9 +299,9 @@ With the use of Bootstrap's border and background
299299

300300
## Transforms
301301

302-
BootstrapVue icons provide several props for applying basic CSS transforms to the `<svg>`. All
302+
BootstrapVue icons provide several props for applying basic SVG transforms to the `<svg>`. All
303303
transforms can be combined for added effect. Note that the transforms are applied to the `<svg>`
304-
content, and not the `<svg>` bounding box.
304+
_content_ and not the `<svg>` bounding box.
305305

306306
### Flipping
307307

src/icons/helpers/make-icon.js

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,35 +62,43 @@ const BVIconBase = {
6262
...commonIconProps
6363
},
6464
render(h, { data, props }) {
65-
const fontScale = toFloat(props.fontScale) || 1
66-
const scale = toFloat(props.scale) || 1
65+
const fontScale = Math.max(toFloat(props.fontScale) || 1, 0) || 1
66+
const scale = Math.max(toFloat(props.scale) || 1, 0) || 1
6767
const rotate = toFloat(props.rotate) || 0
6868
const shiftH = toFloat(props.shiftH) || 0
6969
const shiftV = toFloat(props.shiftV) || 0
7070
const flipH = props.flipH
7171
const flipV = props.flipV
72-
// Compute the transforms. Note that order is important
73-
// CSS transforms are applied in order from right to left
74-
// and we want flipping to occur before rotation, and
75-
// shifting is applied last
72+
// Compute the transforms. Note that order is important as
73+
// SVG transforms are applied in order from left to right
74+
// and we want flipping/scale to occur before rotation.
75+
// Note shifting is applied separately. Assumes that the
76+
// viewbox is `0 0 20 20` (`10 10` is the center)
77+
const hasScale = flipH || flipV || scale !== 1
78+
const hasTransforms = hasScale || rotate
79+
const hasShift = shiftH || shiftV
7680
const transforms = [
77-
shiftH ? `translateX(${(100 * shiftH) / 16}%)` : null,
78-
shiftV ? `translateY(${(-100 * shiftV) / 16}%)` : null,
79-
rotate ? `rotate(${rotate}deg)` : null,
80-
flipH || flipV || scale !== 1
81-
? `scale(${(flipH ? -1 : 1) * scale}, ${(flipV ? -1 : 1) * scale})`
82-
: null
81+
hasTransforms ? 'translate(10 10)' : null,
82+
hasScale ? `scale(${(flipH ? -1 : 1) * scale} ${(flipV ? -1 : 1) * scale})` : null,
83+
rotate ? `rotate(${rotate})` : null,
84+
hasTransforms ? 'translate(-10 -10)' : null
8385
].filter(identity)
8486

85-
// We wrap the content in a `<g>` for handling the transforms
86-
const $inner = h('g', {
87-
style: {
88-
transform: transforms.join(' ') || null,
89-
transformOrigin: transforms.length > 0 ? 'center' : null
90-
},
87+
// We wrap the content in a `<g>` for handling the transforms (except shift)
88+
let $inner = h('g', {
89+
attrs: { transform: transforms.join(' ') || null },
9190
domProps: { innerHTML: props.content || '' }
9291
})
9392

93+
// If needed, we wrap in an additional `<g>` in order to handle the shifting
94+
if (hasShift) {
95+
$inner = h(
96+
'g',
97+
{ attrs: { transform: `translate(${(20 * shiftH) / 16} ${(-20 * shiftV) / 16})` } },
98+
[$inner]
99+
)
100+
}
101+
94102
return h(
95103
'svg',
96104
mergeData(

0 commit comments

Comments
 (0)