Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: uploaded svg icon not showing #3179

Merged
merged 24 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
beb220a
fix: add prio for fill
Arukuen May 6, 2024
3f2d8a1
fix: add prio for fill of arrow in carousel
Arukuen May 6, 2024
adb6957
fix: add prio by using fill in path in map block
Arukuen May 7, 2024
da6db7b
fix: remove custom width and height to allow stackable to adjust it
Arukuen May 8, 2024
c67bdd2
fix: add !important to fill and color to have prio over inline
Arukuen May 8, 2024
4a75f0b
fix: only remove width/height in SVG; support for double and single q…
Arukuen May 12, 2024
9fb0b79
fix: add support for common svg shapes
Arukuen May 12, 2024
95b3717
fix: add support for common svg shapes in carousel
Arukuen May 12, 2024
e6babe1
fix: add support for common svg shapes in map
Arukuen May 12, 2024
57851c1
fix: remove manual setting of fill (default to black if no color is s…
Arukuen May 12, 2024
66b2f2e
fix: add prio for fill
Arukuen May 6, 2024
afec6c3
fix: add prio for fill of arrow in carousel
Arukuen May 6, 2024
d6594b2
fix: add prio by using fill in path in map block
Arukuen May 7, 2024
78164a6
fix: remove custom width and height to allow stackable to adjust it
Arukuen May 8, 2024
e025c4c
fix: add !important to fill and color to have prio over inline
Arukuen May 8, 2024
ee1e376
fix: only remove width/height in SVG; support for double and single q…
Arukuen May 12, 2024
ef7c6a9
fix: add support for common svg shapes
Arukuen May 12, 2024
3e388e4
fix: add support for common svg shapes in carousel
Arukuen May 12, 2024
58e7fef
fix: add support for common svg shapes in map
Arukuen May 12, 2024
5fc35e6
fix: remove manual setting of fill (default to black if no color is s…
Arukuen May 12, 2024
f1cfccb
fix: deprecation
Arukuen May 27, 2024
2632172
fix: deprecation
Arukuen May 27, 2024
6454c0b
fix: remove deprecated code
Arukuen May 27, 2024
43dcf94
fix: handle deprecation in depracated.js
Arukuen Jun 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/block/carousel/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ const Styles = props => {
key="arrowIconColor"
hover="all"
/>
<BlockCss
{ ...propsToPass }
selector=".stk-block-carousel__button svg.ugb-custom-icon :is(g,path,rect,polygon,ellipse)"
hoverSelector=".stk-block-carousel__button svg.ugb-custom-icon :is(g,path,rect,polygon,ellipse):hover"
styleRule="fill"
attrName="arrowIconColor"
key="arrowIconColor"
hover="all"
/>
<BlockCss
{ ...propsToPass }
styleRule="--button-width"
Expand Down
6 changes: 6 additions & 0 deletions src/block/icon-list-item/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
border-width: 1px;
border-color: rgba(0, 0, 0, 0.4);
}

// Apply the color to the SVG path on the defintion
svg.ugb-custom-icon :is(g,path,rect,polygon,ellipse) {
fill: var(--stk-icon-list-marker-color) !important;
color: var(--stk-icon-list-marker-color) !important;
}
}

.stk-block-icon-list-item__content {
Expand Down
12 changes: 12 additions & 0 deletions src/block/map/deprecated.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
import { getIconOptions } from './util'

import { Save } from './save'
import { attributes } from './schema'

import { withVersion } from '~stackable/higher-order'
import { semverCompare } from '~stackable/util'
import {
deprecateBlockBackgroundColorOpacity, deprecateContainerBackgroundColorOpacity,
deprecateBlockShadowColor, deprecateContainerShadowColor,
} from '~stackable/block-components'

import { addFilter } from '@wordpress/hooks'

addFilter( 'stackable.map.util.applySVGAttributes', 'stackable/3.13.0', ( output, attribute, props ) => {
if ( semverCompare( props.version, '<', '3.13.0' ) ) {
return getIconOptions( attribute, true )
}
return output
} )

const deprecated = [
{
// Support the new shadow color.
Expand Down
10 changes: 9 additions & 1 deletion src/block/map/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { i18n, version as VERSION } from 'stackable'
import { __ } from '@wordpress/i18n'
import { compose } from '@wordpress/compose'
import { RawHTML } from '@wordpress/element'
import { applyFilters } from '@wordpress/hooks'

export const Save = props => {
const {
Expand Down Expand Up @@ -90,7 +91,14 @@ export const Save = props => {
<div
data-map-options={ JSON.stringify( mapOptions ) }
data-marker-options={ JSON.stringify( markerOptions ) }
data-icon-options={ JSON.stringify( getIconOptions( attributes ) ) }
data-icon-options={ JSON.stringify(
applyFilters(
'stackable.map.util.applySVGAttributes',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend changing the name of this filter because if you look at where this filter is being used, it's not related to util.applySVGAttributes. I feel like stackable.map.icon-options makes more sense here:

Suggested change
'stackable.map.util.applySVGAttributes',
'stackable.map.icon-options',

Also change the corresponding code that uses this filter

getIconOptions( attributes, false ),
attributes,
props
)
) }
className="stk-block-map__canvas"
/>
)
Expand Down
16 changes: 13 additions & 3 deletions src/block/map/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const getMapStyles = ( { mapStyle, customMapStyle } ) => {
return styleJSON
}

export const getIconOptions = attributes => {
export const getIconOptions = ( attributes, isDeprecated ) => {
const {
icon,
iconColor1,
Expand All @@ -55,9 +55,19 @@ export const getIconOptions = attributes => {
// If we can't use the generated SVG element for any reason we
// display the default icon.
return null
}
}

if ( isDeprecated ) {
// Deprecate this since sets the fill to the default color black, even when no color is selected.
svgEl.firstElementChild.setAttribute( 'fill', 'currentColor' )
} else if ( iconColor1 ) {
// Apply the fill directly to the SVG shapes
const svgShapes = svgEl.querySelectorAll( 'g,path,rect,polygon,ellipse' )
svgShapes.forEach( svgShape => {
svgShape.setAttribute( 'style', `fill: ${ iconColor1 }` )
} )
}

svgEl.firstElementChild.setAttribute( 'fill', 'currentColor' )
const svgIconSize = iconSize ? parseInt( iconSize, 10 ) : DEFAULT_ICON_SIZE
svgEl.setAttribute( 'height', svgIconSize )
svgEl.setAttribute( 'width', svgIconSize )
Expand Down
4 changes: 4 additions & 0 deletions src/components/icon-search-popover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ export const cleanSvgString = svgString => {
newSvg = newSvg.replace( /\s*<g\s*>([\s\S]*?)<\/g>\s*/gm, '$1' )
}

// Remove width and height attribute so that we can control the size (default to 100%)
newSvg = newSvg.replace( /<svg([^>]*)width=(["'])[^"']*["']([^>]*)/g, '<svg$1$3' )
.replace( /<svg([^>]*)height=(["'])[^"']*["']([^>]*)/g, '<svg$1$3' )

return newSvg
}

Expand Down
Loading