mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-24 23:55:53 +00:00
fa2faf563f
In Codex v0.7.0, the CdxButton's `type` prop changed. The `type` prop was renamed `weight` and will continue to accept the same values ('normal', 'quiet', and 'primary'). A new `type` prop was added that accepts the old types, plus native button types ('button', 'reset', and 'submit'). In a future release of Codex, the `type` prop will be removed altogether and the native type can be bound to the CdxButton via the `type` attribute. So, while the old values for `type` still work, we want to update the prop name in anticipation of the `type` prop's removal. For any new code moving forward, the `weight` prop should be used. This patch: - Updates the Button stories to change the `type` prop to `weight` - Updates Codex dev dependencies to v0.7.0 - Updates Storybook webpack config so it can process *.mjs files (Codex ES dist files now have this extension, see Ic29c891c8d7ac705d016aa6f91c5f63684d7d7c8) Bug: T312987 Change-Id: If98dad4769ed72900dbae579823a356669d6cf64
196 lines
3.7 KiB
JavaScript
196 lines
3.7 KiB
JavaScript
import { CdxIcon, CdxButton } from '@wikimedia/codex';
|
|
import '../node_modules/@wikimedia/codex/dist/codex.style.css';
|
|
import { h, createApp } from 'vue';
|
|
import buttonTemplate from '!!raw-loader!../includes/templates/Button.mustache';
|
|
import mustache from 'mustache';
|
|
import { cdxIconAdd } from '@wikimedia/codex-icons';
|
|
|
|
export default {
|
|
title: 'Icon and Buttons'
|
|
};
|
|
|
|
/**
|
|
*
|
|
* @typedef {Object} ButtonProps
|
|
* @property {string} weight
|
|
* @property {string} action
|
|
*/
|
|
/**
|
|
* @param {ButtonProps} props
|
|
* @param {string} label
|
|
* @return {string}
|
|
*/
|
|
function makeButtonLegacy( props, label ) {
|
|
let typeClass = '';
|
|
let iconClass = 'mw-ui-icon-add';
|
|
switch ( props.action ) {
|
|
case 'progressive':
|
|
typeClass += ' mw-ui-progressive';
|
|
iconClass += '-progressive';
|
|
break;
|
|
case 'destructive':
|
|
typeClass += ' mw-ui-destructive';
|
|
iconClass += '-destructive';
|
|
break;
|
|
}
|
|
if ( props.weight === 'primary' ) {
|
|
iconClass = 'mw-ui-icon-add-invert';
|
|
}
|
|
return mustache.render( buttonTemplate, {
|
|
label,
|
|
class: typeClass,
|
|
'is-quiet': props.weight === 'quiet',
|
|
'html-vector-button-icon': `<span class="mw-ui-icon ${iconClass}"></span>`
|
|
} );
|
|
}
|
|
|
|
/**
|
|
* @param {ButtonProps} props
|
|
* @param {string} text
|
|
* @param {string} icon
|
|
* @return {string}
|
|
*/
|
|
function makeButton( props, text, icon ) {
|
|
const el = document.createElement( 'div' );
|
|
const vm = createApp( {
|
|
render: function () {
|
|
// @ts-ignore
|
|
return h( CdxButton, props, [
|
|
h( CdxIcon, { icon } ),
|
|
text
|
|
] );
|
|
}
|
|
} );
|
|
vm.mount( el );
|
|
return `
|
|
<tr>
|
|
<td>${makeButtonLegacy( props, text )}</td>
|
|
<td>${el.outerHTML}</td>
|
|
</tr>`;
|
|
}
|
|
|
|
/**
|
|
* @return {string}
|
|
*/
|
|
function makeIcon() {
|
|
const el = document.createElement( 'div' );
|
|
const vm = createApp( {
|
|
render: function () {
|
|
// @ts-ignore
|
|
return h( CdxButton, {
|
|
'aria-label': 'add'
|
|
}, [
|
|
h( CdxIcon, { icon: cdxIconAdd } )
|
|
] );
|
|
}
|
|
} );
|
|
vm.mount( el );
|
|
const elQuiet = document.createElement( 'div' );
|
|
const vmQuiet = createApp( {
|
|
render: function () {
|
|
// @ts-ignore
|
|
return h( CdxButton, {
|
|
weight: 'quiet',
|
|
'aria-label': 'add'
|
|
}, [
|
|
h( CdxIcon, { icon: cdxIconAdd } )
|
|
] );
|
|
}
|
|
} );
|
|
vmQuiet.mount( elQuiet );
|
|
return `
|
|
<tr>
|
|
<td>
|
|
<h6>Regular icon</h6>
|
|
${
|
|
mustache.render( buttonTemplate, {
|
|
label: 'Normal Icon button',
|
|
icon: 'add'
|
|
} )
|
|
}
|
|
</td>
|
|
<td>
|
|
<h6>Regular icon</h6>
|
|
${el.outerHTML}
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<h6>Small icon button</h6>
|
|
${
|
|
mustache.render( buttonTemplate, {
|
|
label: 'Small icon button',
|
|
class: 'mw-ui-icon-small',
|
|
icon: 'add'
|
|
} )
|
|
}
|
|
</td>
|
|
<td>
|
|
<h6>Small icon button</h6>
|
|
${el.outerHTML}</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<h6>Quiet icon button</h6>
|
|
${
|
|
mustache.render( buttonTemplate, {
|
|
label: 'Quiet Icon',
|
|
'is-quiet': true,
|
|
icon: 'add'
|
|
} )
|
|
}
|
|
</td>
|
|
<td>
|
|
<h6>Quiet icon button</h6>
|
|
${elQuiet.outerHTML}</td>
|
|
</tr>`;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param {string[]} btns
|
|
* @return {string}
|
|
*/
|
|
function makeButtons( btns ) {
|
|
return `<table class="vector-storybook-example-table">
|
|
<tbody>
|
|
<tr>
|
|
<th>Legacy</th>
|
|
<th>Codex</th>
|
|
</tr>
|
|
${btns.join( '\n' )}
|
|
</tbody>
|
|
</table>`;
|
|
}
|
|
|
|
/**
|
|
* @return {string}
|
|
*/
|
|
export const Button = () => makeButtons( [
|
|
makeButton( {
|
|
action: 'default',
|
|
weight: 'quiet'
|
|
}, 'Quiet button', cdxIconAdd ),
|
|
makeButton( {
|
|
action: 'progressive',
|
|
weight: 'quiet'
|
|
}, 'Quiet progressive', cdxIconAdd ),
|
|
makeButton( {
|
|
action: 'destructive',
|
|
weight: 'quiet'
|
|
}, 'Quiet destructive', cdxIconAdd ),
|
|
makeButton( {
|
|
action: 'default',
|
|
weight: 'normal'
|
|
}, 'Normal', cdxIconAdd ),
|
|
makeButton( {
|
|
weight: 'primary',
|
|
action: 'progressive'
|
|
}, 'Progressive primary', cdxIconAdd ),
|
|
makeButton( {
|
|
weight: 'primary',
|
|
action: 'destructive'
|
|
}, 'Destructive primary', cdxIconAdd ),
|
|
makeIcon()
|
|
] );
|