UNPKG

@wordpress/block-library

Version:
199 lines (193 loc) 5.53 kB
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; import _objectSpread from "@babel/runtime/helpers/esm/objectSpread"; import { createElement } from "@wordpress/element"; /** * External dependencies */ import classnames from 'classnames'; import { omit, pick } from 'lodash'; /** * WordPress dependencies */ import { G, Path, SVG } from '@wordpress/components'; import { __, _x } from '@wordpress/i18n'; import { RichText, getColorClassName } from '@wordpress/block-editor'; /** * Internal dependencies */ import edit from './edit'; var blockAttributes = { url: { type: 'string', source: 'attribute', selector: 'a', attribute: 'href' }, title: { type: 'string', source: 'attribute', selector: 'a', attribute: 'title' }, text: { type: 'string', source: 'html', selector: 'a' }, backgroundColor: { type: 'string' }, textColor: { type: 'string' }, customBackgroundColor: { type: 'string' }, customTextColor: { type: 'string' } }; export var name = 'core/button'; var colorsMigration = function colorsMigration(attributes) { return omit(_objectSpread({}, attributes, { customTextColor: attributes.textColor && '#' === attributes.textColor[0] ? attributes.textColor : undefined, customBackgroundColor: attributes.color && '#' === attributes.color[0] ? attributes.color : undefined }), ['color', 'textColor']); }; export var settings = { title: __('Button'), description: __('Prompt visitors to take action with a button-style link.'), icon: createElement(SVG, { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg" }, createElement(Path, { fill: "none", d: "M0 0h24v24H0V0z" }), createElement(G, null, createElement(Path, { d: "M19 6H5c-1.1 0-2 .9-2 2v8c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2zm0 10H5V8h14v8z" }))), category: 'layout', keywords: [__('link')], attributes: blockAttributes, supports: { align: true, alignWide: false }, styles: [{ name: 'default', label: _x('Default', 'block style'), isDefault: true }, { name: 'outline', label: __('Outline') }, { name: 'squared', label: _x('Squared', 'block style') }], edit: edit, save: function save(_ref) { var _classnames; var attributes = _ref.attributes; var url = attributes.url, text = attributes.text, title = attributes.title, backgroundColor = attributes.backgroundColor, textColor = attributes.textColor, customBackgroundColor = attributes.customBackgroundColor, customTextColor = attributes.customTextColor; var textClass = getColorClassName('color', textColor); var backgroundClass = getColorClassName('background-color', backgroundColor); var buttonClasses = classnames('wp-block-button__link', (_classnames = { 'has-text-color': textColor || customTextColor }, _defineProperty(_classnames, textClass, textClass), _defineProperty(_classnames, 'has-background', backgroundColor || customBackgroundColor), _defineProperty(_classnames, backgroundClass, backgroundClass), _classnames)); var buttonStyle = { backgroundColor: backgroundClass ? undefined : customBackgroundColor, color: textClass ? undefined : customTextColor }; return createElement("div", null, createElement(RichText.Content, { tagName: "a", className: buttonClasses, href: url, title: title, style: buttonStyle, value: text })); }, deprecated: [{ attributes: _objectSpread({}, pick(blockAttributes, ['url', 'title', 'text']), { color: { type: 'string' }, textColor: { type: 'string' }, align: { type: 'string', default: 'none' } }), save: function save(_ref2) { var attributes = _ref2.attributes; var url = attributes.url, text = attributes.text, title = attributes.title, align = attributes.align, color = attributes.color, textColor = attributes.textColor; var buttonStyle = { backgroundColor: color, color: textColor }; var linkClass = 'wp-block-button__link'; return createElement("div", { className: "align".concat(align) }, createElement(RichText.Content, { tagName: "a", className: linkClass, href: url, title: title, style: buttonStyle, value: text })); }, migrate: colorsMigration }, { attributes: _objectSpread({}, pick(blockAttributes, ['url', 'title', 'text']), { color: { type: 'string' }, textColor: { type: 'string' }, align: { type: 'string', default: 'none' } }), save: function save(_ref3) { var attributes = _ref3.attributes; var url = attributes.url, text = attributes.text, title = attributes.title, align = attributes.align, color = attributes.color, textColor = attributes.textColor; return createElement("div", { className: "align".concat(align), style: { backgroundColor: color } }, createElement(RichText.Content, { tagName: "a", href: url, title: title, style: { color: textColor }, value: text })); }, migrate: colorsMigration }] }; //# sourceMappingURL=index.js.map