-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2418 from vektor-inc/feature/icon/empty-atag-acce…
…ssibility [ アイコン ]ツールバーからのリンク指定機能にnoreferrer、nofollow、link descriptionオプションを追加
- Loading branch information
Showing
10 changed files
with
288 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
import { Component } from '@wordpress/element'; | ||
import parse from 'html-react-parser'; | ||
import { isHexColor } from '@vkblocks/utils/is-hex-color'; | ||
|
||
export class VKBIcon extends Component { | ||
render() { | ||
let fontAwesomeIcon = this.props.lbFontAwesomeIcon; | ||
const iconSize = this.props.lbSize; | ||
const iconSizeUnit = this.props.lbSizeUnit; | ||
const iconMargin = this.props.lbMargin; | ||
const iconMarginUnit = this.props.lbMarginUnit; | ||
const iconRadius = this.props.lbRadius; | ||
const iconAlign = this.props.lbAlign; | ||
const iconType = this.props.lbType; | ||
const iconColor = this.props.lbColor; | ||
const iconFontColor = this.props.lbFontColor; | ||
const iconUrl = this.props.lbUrl; | ||
const iconTarget = this.props.lbTarget; | ||
|
||
// outer & align | ||
let outerClass = 'vk_icon_frame'; | ||
if (iconAlign === 'center') { | ||
outerClass += ' text-center'; | ||
} else if (iconAlign === 'right') { | ||
outerClass += ' text-right'; | ||
} | ||
|
||
// color style | ||
let borderClass = 'vk_icon_border'; | ||
let borderStyle = {}; | ||
|
||
if (iconType === '0') { | ||
// Solid color | ||
if ( | ||
iconColor !== 'undefined' && | ||
iconColor !== null && | ||
iconColor !== undefined | ||
) { | ||
// Solid color | ||
borderClass += ` has-background`; | ||
|
||
if (isHexColor(iconColor)) { | ||
// custom color | ||
borderStyle = { | ||
backgroundColor: `${iconColor}`, | ||
}; | ||
} else { | ||
// palette color | ||
borderClass += ` has-${iconColor}-background-color`; | ||
} | ||
} | ||
} else { | ||
if ( | ||
iconColor !== 'undefined' && | ||
iconColor !== null && | ||
iconColor !== undefined | ||
) { | ||
borderClass += ` has-text-color`; | ||
|
||
if (isHexColor(iconColor)) { | ||
// custom color | ||
borderStyle = { | ||
color: `${iconColor}`, | ||
}; | ||
} else { | ||
// palette color | ||
borderClass += ` has-${iconColor}-color`; | ||
} | ||
} | ||
|
||
if (iconType === '1') { | ||
// Icon & Frame | ||
outerClass += ' is-style-outline'; | ||
} else { | ||
// icon only | ||
outerClass += ' is-style-noline'; | ||
} | ||
} | ||
|
||
// margin | ||
if ( | ||
!( | ||
iconSize === 36 && | ||
iconSizeUnit === 'px' && | ||
iconMargin === 22 && | ||
iconMarginUnit === 'px' | ||
) | ||
) { | ||
borderStyle.width = | ||
'calc(' + | ||
(iconSize + iconSizeUnit) + | ||
' + ' + | ||
(iconMargin * 2 + iconMarginUnit) + | ||
')'; | ||
borderStyle.height = borderStyle.width; | ||
} | ||
|
||
// border radius | ||
if (iconRadius !== 50) { | ||
borderStyle.borderRadius = iconRadius + `%`; | ||
} | ||
|
||
// icon font | ||
let faIconTag = ''; | ||
if (fontAwesomeIcon) { | ||
fontAwesomeIcon = fontAwesomeIcon.replace(/ fas/g, 'fas'); | ||
|
||
// font size | ||
let fontStyle = ``; | ||
let fontClass = ` vk_icon_font `; | ||
if (!(iconSize === 36 && iconSizeUnit === 'px')) { | ||
fontStyle = ` font-size:${iconSize}${iconSizeUnit};`; | ||
} | ||
|
||
// icon color | ||
if ( | ||
iconFontColor !== 'undefined' && | ||
iconFontColor !== null && | ||
iconFontColor !== undefined | ||
) { | ||
if (isHexColor(iconFontColor)) { | ||
// custom color | ||
fontStyle += ` color:${iconFontColor};`; | ||
} else { | ||
// palette color | ||
fontClass += ` has-text-color has-${iconFontColor}-color `; | ||
} | ||
} | ||
|
||
// add class and inline css | ||
const faIconFragment = fontAwesomeIcon.split(' '); | ||
faIconFragment[0] = faIconFragment[0] + ` style="${fontStyle};"`; | ||
faIconFragment[1] = ' ' + faIconFragment[1] + fontClass; | ||
faIconTag = faIconFragment.join(''); | ||
} | ||
|
||
const blockContent = ( | ||
<> | ||
<div className={borderClass} style={borderStyle}> | ||
{parse(faIconTag)} | ||
</div> | ||
</> | ||
); | ||
|
||
let blockContentWrapper = ''; | ||
if (iconUrl !== null && iconUrl !== undefined && iconUrl !== '') { | ||
blockContentWrapper = ( | ||
/* | ||
target=_blankで指定すると、WordPressが自動でnoopener noreferrerを付与する。 | ||
ブロックでもrelを付与しないとブロックが壊れる。 | ||
*/ | ||
<a | ||
href={iconUrl} | ||
className="vk_icon_link" | ||
target={iconTarget && '_blank'} | ||
rel={iconTarget && 'noopener noreferrer'} | ||
> | ||
{blockContent} | ||
</a> | ||
); | ||
} else { | ||
blockContentWrapper = blockContent; | ||
} | ||
|
||
return ( | ||
<> | ||
<div className={outerClass}>{blockContentWrapper}</div> | ||
</> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { VKBIcon } from './component'; | ||
import { useBlockProps } from '@wordpress/block-editor'; | ||
|
||
export default function save({ attributes }) { | ||
let { | ||
faIcon, | ||
iconSize, | ||
iconSizeUnit, | ||
iconMargin, | ||
iconMarginUnit, | ||
iconRadius, | ||
iconAlign, | ||
iconType, | ||
iconColor, | ||
iconFontColor, | ||
iconUrl, | ||
iconTarget, | ||
} = attributes; | ||
|
||
if (faIcon && !faIcon.match(/<i/)) { | ||
faIcon = `<i class="${faIcon}"></i>`; | ||
} | ||
|
||
const blockProps = useBlockProps.save({ | ||
className: `vk_icon`, | ||
}); | ||
|
||
return ( | ||
<div {...blockProps}> | ||
<VKBIcon | ||
lbFontAwesomeIcon={faIcon} | ||
lbSize={iconSize} | ||
lbSizeUnit={iconSizeUnit} | ||
lbMargin={iconMargin} | ||
lbMarginUnit={iconMarginUnit} | ||
lbRadius={iconRadius} | ||
lbAlign={iconAlign} | ||
lbType={iconType} | ||
lbColor={iconColor} | ||
lbFontColor={iconFontColor} | ||
lbUrl={iconUrl} | ||
lbTarget={iconTarget} | ||
/> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
test/e2e-tests/fixtures/blocks/vk-blocks__icon__deprecated-1-94-2.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<!-- wp:vk-blocks/icon {"iconFontColor":"#ffff00"} --> | ||
<div class="wp-block-vk-blocks-icon vk_icon"><div class="vk_icon_frame"><div class="vk_icon_border"><i style="color:#ffff00" class="fas vk_icon_font fa-user"></i></div></div></div> | ||
<!-- /wp:vk-blocks/icon --> |
3 changes: 3 additions & 0 deletions
3
test/e2e-tests/fixtures/blocks/vk-blocks__icon__deprecated-1-94-2__link.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<!-- wp:vk-blocks/icon {"iconFontColor":"#ffff00","iconUrl":"http://localhost:8888/","iconTarget":true,"relAttribute":"noreferrer nofollow","linkDescription":"test"} --> | ||
<div class="wp-block-vk-blocks-icon vk_icon"><div class="vk_icon_frame"><a href="http://localhost:8888/" class="vk_icon_link" target="_blank" rel="noreferrer nofollow"><span class="screen-reader-text">test</span><div class="vk_icon_border"><i style="color:#ffff00" class="fas vk_icon_font fa-user"></i></div></a></div></div> | ||
<!-- /wp:vk-blocks/icon --> |