2022-02-01 20:52:16 +00:00
|
|
|
import { CdxIcon, CdxButton } from '@wikimedia/codex';
|
|
|
|
import '../node_modules/@wikimedia/codex/dist/codex.style.css';
|
|
|
|
import { h, createApp } from 'vue';
|
2021-09-08 18:14:29 +00:00
|
|
|
import buttonTemplate from '!!raw-loader!../includes/templates/Button.mustache';
|
|
|
|
import mustache from 'mustache';
|
2022-02-01 20:52:16 +00:00
|
|
|
import { cdxIconAdd } from '@wikimedia/codex-icons';
|
2021-09-01 22:58:54 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
title: 'Icon and Buttons'
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @typedef {Object} ButtonProps
|
Rename CdxButton `type` prop to `weight`
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
2023-03-16 21:02:15 +00:00
|
|
|
* @property {string} weight
|
2021-09-01 22:58:54 +00:00
|
|
|
* @property {string} action
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @param {ButtonProps} props
|
2021-09-08 18:14:29 +00:00
|
|
|
* @param {string} label
|
2021-09-01 22:58:54 +00:00
|
|
|
* @return {string}
|
|
|
|
*/
|
2021-09-08 18:14:29 +00:00
|
|
|
function makeButtonLegacy( props, label ) {
|
2021-09-01 22:58:54 +00:00
|
|
|
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;
|
|
|
|
}
|
Rename CdxButton `type` prop to `weight`
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
2023-03-16 21:02:15 +00:00
|
|
|
if ( props.weight === 'primary' ) {
|
2021-09-01 22:58:54 +00:00
|
|
|
iconClass = 'mw-ui-icon-add-invert';
|
|
|
|
}
|
2021-09-08 18:14:29 +00:00
|
|
|
return mustache.render( buttonTemplate, {
|
|
|
|
label,
|
|
|
|
class: typeClass,
|
Rename CdxButton `type` prop to `weight`
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
2023-03-16 21:02:15 +00:00
|
|
|
'is-quiet': props.weight === 'quiet',
|
2021-09-08 18:14:29 +00:00
|
|
|
'html-vector-button-icon': `<span class="mw-ui-icon ${iconClass}"></span>`
|
|
|
|
} );
|
2021-09-01 22:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {ButtonProps} props
|
|
|
|
* @param {string} text
|
|
|
|
* @param {string} icon
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
function makeButton( props, text, icon ) {
|
|
|
|
const el = document.createElement( 'div' );
|
2022-02-01 20:52:16 +00:00
|
|
|
const vm = createApp( {
|
|
|
|
render: function () {
|
|
|
|
// @ts-ignore
|
|
|
|
return h( CdxButton, props, [
|
|
|
|
h( CdxIcon, { icon } ),
|
2021-09-01 22:58:54 +00:00
|
|
|
text
|
|
|
|
] );
|
|
|
|
}
|
|
|
|
} );
|
2022-02-01 20:52:16 +00:00
|
|
|
vm.mount( el );
|
2021-09-01 22:58:54 +00:00
|
|
|
return `
|
|
|
|
<tr>
|
|
|
|
<td>${makeButtonLegacy( props, text )}</td>
|
2022-02-01 20:52:16 +00:00
|
|
|
<td>${el.outerHTML}</td>
|
2021-09-01 22:58:54 +00:00
|
|
|
</tr>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
function makeIcon() {
|
2022-09-13 21:39:47 +00:00
|
|
|
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, {
|
Rename CdxButton `type` prop to `weight`
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
2023-03-16 21:02:15 +00:00
|
|
|
weight: 'quiet',
|
2022-09-13 21:39:47 +00:00
|
|
|
'aria-label': 'add'
|
|
|
|
}, [
|
|
|
|
h( CdxIcon, { icon: cdxIconAdd } )
|
|
|
|
] );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
vmQuiet.mount( elQuiet );
|
2021-09-01 22:58:54 +00:00
|
|
|
return `
|
|
|
|
<tr>
|
|
|
|
<td>
|
2022-09-13 21:39:47 +00:00
|
|
|
<h6>Regular icon</h6>
|
2021-09-08 18:14:29 +00:00
|
|
|
${
|
|
|
|
mustache.render( buttonTemplate, {
|
2022-09-13 21:39:47 +00:00
|
|
|
label: 'Normal Icon button',
|
2021-09-08 18:14:29 +00:00
|
|
|
icon: 'add'
|
|
|
|
} )
|
|
|
|
}
|
2021-09-01 22:58:54 +00:00
|
|
|
</td>
|
2022-09-13 21:39:47 +00:00
|
|
|
<td>
|
|
|
|
<h6>Regular icon</h6>
|
|
|
|
${el.outerHTML}
|
|
|
|
</td>
|
2021-09-01 22:58:54 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>
|
2022-09-13 21:39:47 +00:00
|
|
|
<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>
|
2021-09-08 18:14:29 +00:00
|
|
|
${
|
|
|
|
mustache.render( buttonTemplate, {
|
|
|
|
label: 'Quiet Icon',
|
|
|
|
'is-quiet': true,
|
|
|
|
icon: 'add'
|
|
|
|
} )
|
|
|
|
}
|
2021-09-01 22:58:54 +00:00
|
|
|
</td>
|
2022-09-13 21:39:47 +00:00
|
|
|
<td>
|
|
|
|
<h6>Quiet icon button</h6>
|
|
|
|
${elQuiet.outerHTML}</td>
|
2021-09-01 22:58:54 +00:00
|
|
|
</tr>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {string[]} btns
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
function makeButtons( btns ) {
|
2022-09-13 21:39:47 +00:00
|
|
|
return `<table class="vector-storybook-example-table">
|
2021-09-01 22:58:54 +00:00
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<th>Legacy</th>
|
2022-02-01 20:52:16 +00:00
|
|
|
<th>Codex</th>
|
2021-09-01 22:58:54 +00:00
|
|
|
</tr>
|
|
|
|
${btns.join( '\n' )}
|
|
|
|
</tbody>
|
|
|
|
</table>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
export const Button = () => makeButtons( [
|
|
|
|
makeButton( {
|
|
|
|
action: 'default',
|
Rename CdxButton `type` prop to `weight`
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
2023-03-16 21:02:15 +00:00
|
|
|
weight: 'quiet'
|
2022-02-01 20:52:16 +00:00
|
|
|
}, 'Quiet button', cdxIconAdd ),
|
2021-09-01 22:58:54 +00:00
|
|
|
makeButton( {
|
|
|
|
action: 'progressive',
|
Rename CdxButton `type` prop to `weight`
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
2023-03-16 21:02:15 +00:00
|
|
|
weight: 'quiet'
|
2022-02-01 20:52:16 +00:00
|
|
|
}, 'Quiet progressive', cdxIconAdd ),
|
2021-09-01 22:58:54 +00:00
|
|
|
makeButton( {
|
|
|
|
action: 'destructive',
|
Rename CdxButton `type` prop to `weight`
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
2023-03-16 21:02:15 +00:00
|
|
|
weight: 'quiet'
|
2022-02-01 20:52:16 +00:00
|
|
|
}, 'Quiet destructive', cdxIconAdd ),
|
2021-09-01 22:58:54 +00:00
|
|
|
makeButton( {
|
|
|
|
action: 'default',
|
Rename CdxButton `type` prop to `weight`
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
2023-03-16 21:02:15 +00:00
|
|
|
weight: 'normal'
|
2022-02-01 20:52:16 +00:00
|
|
|
}, 'Normal', cdxIconAdd ),
|
2021-09-01 22:58:54 +00:00
|
|
|
makeButton( {
|
Rename CdxButton `type` prop to `weight`
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
2023-03-16 21:02:15 +00:00
|
|
|
weight: 'primary',
|
2021-09-01 22:58:54 +00:00
|
|
|
action: 'progressive'
|
2022-02-01 20:52:16 +00:00
|
|
|
}, 'Progressive primary', cdxIconAdd ),
|
2021-09-01 22:58:54 +00:00
|
|
|
makeButton( {
|
Rename CdxButton `type` prop to `weight`
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
2023-03-16 21:02:15 +00:00
|
|
|
weight: 'primary',
|
2021-09-01 22:58:54 +00:00
|
|
|
action: 'destructive'
|
2022-02-01 20:52:16 +00:00
|
|
|
}, 'Destructive primary', cdxIconAdd ),
|
2021-09-01 22:58:54 +00:00
|
|
|
makeIcon()
|
|
|
|
] );
|