< 用户:玲子
| 无编辑摘要 标签:已被回退 | 无编辑摘要 标签:手工回退 | ||
| 第1行: | 第1行: | ||
| // Add a "Codex Widgets" portlet to the main menu | |||
| mw.util.addPortlet( 'p-codex', 'Codex Widgets', '#p-interaction' ); | |||
| const dialogTrigger = mw.util.addPortletLink( 'p-codex', '#', 'Example Dialog Widget', 'p-codex-dialog' ); | |||
| mw.loader.using( '@wikimedia/codex' ).then( function( require ) { | mw.loader.using( '@wikimedia/codex' ).then( function( require ) { | ||
| 	const Vue = require( 'vue' ); | |||
| 	/ | 	const Codex = require( '@wikimedia/codex' ); | ||
| 	const mountPoint = document.body.appendChild( document.createElement( 'div' ) ); | 	const mountPoint = document.body.appendChild( document.createElement( 'div' ) ); | ||
| 	Vue.createMwApp( { | 	Vue.createMwApp( { | ||
| 		//  | 		data: function() { | ||
| 	} ).mount( mountPoint ); | 			return { | ||
| 				showDialog: false, | |||
| 				count: 0, | |||
| 				codexLink: 'https://doc.wikimedia.org/codex/latest/' | |||
| 			}; | |||
| 		}, | |||
| 		template: ` | |||
| 			<cdx-dialog v-model:open="showDialog" | |||
| 				title="Hello from Codex" | |||
| 				close-button-label="Close" | |||
| 				:default-action="defaultAction" | |||
| 				@default="open = false" | |||
| 			> | |||
| 				<p>This Dialog component comes from Codex, the new design system for Wikimedia.</p> | |||
| 				<p>To learn more about Codex, check out the documentation <a :href="codexLink" target="_blank">here.</a></p> | |||
| 				<hr /> | |||
| 				<p>Click these buttons to update the reactive count value:</p> | |||
| 				<p>Count: {{ count }}</p> | |||
| 				<p> | |||
| 					<cdx-button action="destructive" @click="decrement">Decrease</cdx-button> | |||
| 					<cdx-button action="progressive" @click="increment">Increase</cdx-button> | |||
| 				</p> | |||
| 			</cdx-dialog> | |||
| 		`, | |||
| 		methods: { | |||
| 			openDialog () { | |||
| 				this.showDialog = true; | |||
| 			}, | |||
| 			increment() { | |||
| 				this.count++; | |||
| 			}, | |||
| 			decrement() { | |||
| 				this.count--; | |||
| 			} | |||
| 		}, | |||
| 		mounted() { | |||
| 			dialogTrigger.addEventListener( 'click', this.openDialog ); | |||
| 		}, | |||
| 		unMounted() { | |||
| 			dialogTrigger.removeEventListener( this.openDialog ); | |||
| 		} | |||
| 	} ) | |||
| 	.component( 'cdx-button', Codex.CdxButton ) | |||
| 	.component( 'cdx-dialog', Codex.CdxDialog ) | |||
| 	.mount( mountPoint ); | |||
| } ); | } ); | ||
2025年5月28日 (三) 18:28的版本
// Add a "Codex Widgets" portlet to the main menu
mw.util.addPortlet( 'p-codex', 'Codex Widgets', '#p-interaction' );
const dialogTrigger = mw.util.addPortletLink( 'p-codex', '#', 'Example Dialog Widget', 'p-codex-dialog' );
mw.loader.using( '@wikimedia/codex' ).then( function( require ) {
	const Vue = require( 'vue' );
	const Codex = require( '@wikimedia/codex' );
	const mountPoint = document.body.appendChild( document.createElement( 'div' ) );
	
	Vue.createMwApp( {
		data: function() {
			return {
				showDialog: false,
				count: 0,
				codexLink: 'https://doc.wikimedia.org/codex/latest/'
			};
		},
		template: `
			<cdx-dialog v-model:open="showDialog"
				title="Hello from Codex"
				close-button-label="Close"
				:default-action="defaultAction"
				@default="open = false"
			>
				<p>This Dialog component comes from Codex, the new design system for Wikimedia.</p>
				<p>To learn more about Codex, check out the documentation <a :href="codexLink" target="_blank">here.</a></p>
				<hr />
				<p>Click these buttons to update the reactive count value:</p>
				<p>Count: {{ count }}</p>
				<p>
					<cdx-button action="destructive" @click="decrement">Decrease</cdx-button>
					<cdx-button action="progressive" @click="increment">Increase</cdx-button>
				</p>
			</cdx-dialog>
		`,
		methods: {
			openDialog () {
				this.showDialog = true;
			},
			increment() {
				this.count++;
			},
			decrement() {
				this.count--;
			}
		},
		mounted() {
			dialogTrigger.addEventListener( 'click', this.openDialog );
		},
		unMounted() {
			dialogTrigger.removeEventListener( this.openDialog );
		}
	} )
	.component( 'cdx-button', Codex.CdxButton )
	.component( 'cdx-dialog', Codex.CdxDialog )
	.mount( mountPoint );
} );