UNPKG

@wordpress/components

Version:
1 lines • 1.4 kB
{"version":3,"file":"index.cjs","names":[],"sources":["../../src/shortcut/index.tsx"],"sourcesContent":["import type { ShortcutProps } from './types';\n\n/**\n * Shortcut component is used to display keyboard shortcuts, and it can be customized with a custom display and aria label if needed.\n *\n * ```jsx\n * import { Shortcut } from '@wordpress/components';\n *\n * const MyShortcut = () => {\n * \treturn (\n * \t\t<Shortcut shortcut={{ display: 'Ctrl + S', ariaLabel: 'Save' }} />\n * \t);\n * };\n * ```\n */\nfunction Shortcut( props: ShortcutProps ) {\n\tconst { shortcut, className } = props;\n\n\tif ( ! shortcut ) {\n\t\treturn null;\n\t}\n\n\tlet displayText;\n\tlet ariaLabel;\n\n\tif ( typeof shortcut === 'string' ) {\n\t\tdisplayText = shortcut;\n\t}\n\n\tif ( shortcut !== null && typeof shortcut === 'object' ) {\n\t\tdisplayText = shortcut.display;\n\t\tariaLabel = shortcut.ariaLabel;\n\t}\n\n\treturn (\n\t\t<span className={ className } aria-label={ ariaLabel } dir=\"ltr\">\n\t\t\t{ displayText }\n\t\t</span>\n\t);\n}\n\nexport default Shortcut;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAeA,SAAS,SAAU,OAAuB;CACzC,MAAM,EAAE,UAAU,cAAc;CAEhC,IAAK,CAAE,UACN,OAAO;CAGR,IAAI;CACJ,IAAI;CAEJ,IAAK,OAAO,aAAa,UACxB,cAAc;CAGf,IAAK,aAAa,QAAQ,OAAO,aAAa,UAAW;EACxD,cAAc,SAAS;EACvB,YAAY,SAAS;CACtB;CAEA,OACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;EAAkB;EAAY,cAAa;EAAY,KAAI;EACxD,UAAA;CACG,CAAA;AAER"}