UNPKG

@wordpress/block-library

Version:
1 lines • 1.71 kB
{"version":3,"file":"utils.cjs","names":[],"sources":["../../src/button/utils.js"],"sourcesContent":["/**\n * Returns whether the given width value is a percentage.\n *\n * @param {string} width - The width value.\n * @return {boolean} True if the width is a percentage value.\n */\nexport function isPercentageWidth( width ) {\n\treturn typeof width === 'string' && width.endsWith( '%' );\n}\n\n/**\n * Returns the width classes for the button based on the width attribute.\n *\n * @param {string} width - The width value (e.g., '25%', '50%', '75%', '100%', or custom value).\n * @return {Object} Object with width-related class names as keys and true as values.\n */\nexport function getWidthClasses( width ) {\n\tif ( ! width ) {\n\t\treturn {};\n\t}\n\n\tif ( isPercentageWidth( width ) ) {\n\t\tconst legacyWidthClasses = {\n\t\t\t'25%': 'wp-block-button__width-25',\n\t\t\t'50%': 'wp-block-button__width-50',\n\t\t\t'75%': 'wp-block-button__width-75',\n\t\t\t'100%': 'wp-block-button__width-100',\n\t\t};\n\t\treturn {\n\t\t\t'has-custom-width': true,\n\t\t\t'wp-block-button__width': true,\n\t\t\t// Maintain legacy class for backwards compatibility.\n\t\t\t...( legacyWidthClasses[ width ] && {\n\t\t\t\t[ legacyWidthClasses[ width ] ]: true,\n\t\t\t} ),\n\t\t};\n\t}\n\n\treturn {\n\t\t'has-custom-width': true,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;AAMA,SAAgB,kBAAmB,OAAQ;CAC1C,OAAO,OAAO,UAAU,YAAY,MAAM,SAAU,GAAI;AACzD;;;;;;;AAQA,SAAgB,gBAAiB,OAAQ;CACxC,IAAK,CAAE,OACN,OAAO,CAAC;CAGT,IAAK,kBAAmB,KAAM,GAAI;EACjC,MAAM,qBAAqB;GAC1B,OAAO;GACP,OAAO;GACP,OAAO;GACP,QAAQ;EACT;EACA,OAAO;GACN,oBAAoB;GACpB,0BAA0B;GAE1B,GAAK,mBAAoB,UAAW,GACjC,mBAAoB,SAAW,KAClC;EACD;CACD;CAEA,OAAO,EACN,oBAAoB,KACrB;AACD"}