Codex/pt: Difference between revisions
Created page with "Este é um exemplo de um acordeão." |
Updating to match new version of source page |
||
| (24 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
<languages/> |
<languages/> |
||
{{Ambox |
|||
| image = [[File:Codex icon articles color-progressive.svg|40px|link=]] |
|||
| text = Visite o [[wmdoc:codex/latest/|''site'' da documentação oficial]] para detalhes completos do Codex, incluindo como o utilizar fora do MediaWiki. |
|||
}} |
|||
<!-- {{Bundled|1.45}} --> |
<!-- {{Bundled|1.45}} --> |
||
| Line 9: | Line 5: | ||
| name = Codex |
| name = Codex |
||
| logo = Codex logo.svg |
| logo = Codex logo.svg |
||
| description = |
| description = Sistema de desenho para a Wikimédia com linhas diretrizes e um conjunto de ferramentas (códigos de desenho, componentes, e ícones) para criar interfaces do utilizador |
||
| group = [[Codex/Steering Committee|Codex Steering Committee]] |
| group = [[Codex/Steering Committee|Codex Steering Committee]] |
||
| members = [[User:DTorsani-WMF|Derek Torsani]], [[User:Roan Kattouw (WMF)|Roan Kattouw]], [[User:JDrewniak_(WMF)|Jan Drewniak]] |
| members = [[User:DTorsani-WMF|Derek Torsani]], [[User:Roan Kattouw (WMF)|Roan Kattouw]], [[User:JDrewniak_(WMF)|Jan Drewniak]] |
||
| Line 17: | Line 13: | ||
'''Codex''' é o {{ll|MediaWiki user interface framework|sistema de desenho}} oficial para a {{ll|Wikimedia}}. |
'''Codex''' é o {{ll|MediaWiki user interface framework|sistema de desenho}} oficial para a {{ll|Wikimedia}}. |
||
Este fornece um conjunto unificado de ferramentas, linhas diretrizes, e componentes para ajudar os programadores e desenhadores a criarem interfaces do utilizador consistentes, [[wmdoc:codex/latest/style-guide/accessibility.html|acessíveis]] e {{ll|localisation|localizadas}} nos projetos da Wikimédia. |
|||
<span lang="en" dir="ltr" class="mw-content-ltr">Codex enables contributors to use standardized UI components built with {{ll|Vue.js}} |
<span lang="en" dir="ltr" class="mw-content-ltr">Codex enables contributors to use standardized UI components built with {{ll|Vue.js}} or plain {{ll|CSS}}—such as buttons, menus, dialogs, and icons.</span> |
||
<span lang="en" dir="ltr" class="mw-content-ltr">It ensures a consistent look and behavior for our products, so that they align with the visual style and functionality standards of Wikimedia.</span> |
<span lang="en" dir="ltr" class="mw-content-ltr">It ensures a consistent look and behavior for our products, so that they align with the visual style and functionality standards of Wikimedia.</span> |
||
<span lang="en" dir="ltr" class="mw-content-ltr">It supports both developers and designers in creating user-friendly and maintainable interfaces.</span> |
<span lang="en" dir="ltr" class="mw-content-ltr">It supports both developers and designers in creating user-friendly and maintainable interfaces.</span> |
||
Visite o [[wmdoc:codex/latest/|''site'' da documentação oficial]] para detalhes completos do Codex, incluindo como o utilizar fora do MediaWiki. |
|||
{{void|1= |
{{void|1= |
||
Codex inclui: |
Codex inclui: |
||
| Line 31: | Line 29: | ||
* [[wmdoc:codex/latest/composables/overview.html|Composables]] para padrões comuns da IU |
* [[wmdoc:codex/latest/composables/overview.html|Composables]] para padrões comuns da IU |
||
}} |
}} |
||
Codex é o sistema recomendado de desenho da interface do utilizador, e foi incorporado no MediaWiki desde {{ll|MediaWiki 1.39}}. <span lang="en" dir="ltr" class="mw-content-ltr">It is also available as a set of [[wikitech:Npm registry|npm]] packages.</span> |
<span class="mw-translate-fuzzy">Codex é o sistema recomendado de desenho da interface do utilizador, e foi incorporado no MediaWiki desde {{ll|MediaWiki 1.39}}.</span> <span lang="en" dir="ltr" class="mw-content-ltr">It is also available as a set of [[wikitech:Npm registry|npm]] packages.</span> |
||
<span lang="en" dir="ltr" class="mw-content-ltr">The system is collaboratively developed by the {{ll|Wikimedia Foundation}}, Wikimedia Deutschland, and volunteer contributors.</span> |
<span lang="en" dir="ltr" class="mw-content-ltr">The system is collaboratively developed by the {{ll|Wikimedia Foundation}}, Wikimedia Deutschland, and volunteer contributors.</span> |
||
<span lang="en" dir="ltr" class="mw-content-ltr">Codex's source code is hosted [[git:design/codex|on Gerrit]], and its development is tracked [[phab:project/profile/5587/|in Phabricator]].</span> |
<span lang="en" dir="ltr" class="mw-content-ltr">Codex's source code is hosted [[git:design/codex|on Gerrit]], and its development is tracked [[phab:project/profile/5587/|in Phabricator]].</span> |
||
<span lang="en" dir="ltr" class="mw-content-ltr"> |
<span lang="en" dir="ltr" class="mw-content-ltr">Visit the [[git:design/codex/+/refs/heads/main/CHANGELOG.md|full changelog]] and join '''our [https://t.me/+oeXgL95hvgZiMDgx Contributor Telegram group]''' to get involved.</span> |
||
<span id="Basic_usage"></span> |
<span id="Basic_usage"></span> |
||
| Line 46: | Line 44: | ||
}} |
}} |
||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
=== CodexExample MediaWiki extension === |
=== CodexExample MediaWiki extension === |
||
</div> |
|||
<span lang="en" dir="ltr" class="mw-content-ltr">The {{ll|Codex/Steering Committee}} maintains the [[gitlab:repos/design-systems/CodexExample|CodexExample]] MediaWiki extension that demonstrates how to use design tokens, components, and icons from Codex.</span> |
|||
<span lang="en" dir="ltr" class="mw-content-ltr">This extension can be installed (it sets up a dedicated special page called <code>Special:CodexExample</code> with live demos), or you can study its source code for inspiration.</span> |
|||
<span lang="en" dir="ltr" class="mw-content-ltr">See the project [https://gitlab.wikimedia.org/repos/design-systems/CodexExample/-/blob/main/README.md README.md] page for more information on installation and use.</span> |
|||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
The [[Codex/Steering Committee|Codex Steering Committee]] maintains the [[gitlab:repos/design-systems/CodexExample|CodexExample]] MediaWiki extension that demonstrates how to use design tokens, components, and icons from Codex. |
|||
This extension can be installed (it sets up a dedicated special page called {{Mono|Special:CodexExample}} with live demos), or you can study its source code for inspiration. |
|||
See the project {{Mono|[https://gitlab.wikimedia.org/repos/design-systems/CodexExample/-/blob/main/README.md README.md]}} page for more information on installation and use. |
|||
=== Usage with JavaScript === |
=== Usage with JavaScript === |
||
</div> |
|||
{{Note |
{{Note |
||
| text = For improved page load performance, limit loading to a subset of Codex components for |
| text = <span lang="en" dir="ltr" class="mw-content-ltr">For improved page load performance, limit loading to a subset of Codex components for {{ll|skins|skins}} and {{ll|extensions|extensions}}.</span> <span lang="en" dir="ltr" class="mw-content-ltr">See [[#Using a limited subset of components|#Using a limited subset of components]]</span> |
||
}} |
}} |
||
Codex components are built using the |
<span lang="en" dir="ltr" class="mw-content-ltr">Codex components are built using the {{ll|Vue.js}} JavaScript framework.</span> |
||
If you are developing a Vue application in MediaWiki, then it's easy to load Codex components from |
<span lang="en" dir="ltr" class="mw-content-ltr">If you are developing a Vue application in MediaWiki, then it's easy to load Codex components from {{ll|ResourceLoader}} using <code>require()</code>.</span> |
||
You can load all of Codex at once, or just a limited subset of components. |
<span lang="en" dir="ltr" class="mw-content-ltr">You can load all of Codex at once, or just a limited subset of components.</span> |
||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
==== Loading the entire library (recommended for use in userscripts) ==== |
==== Loading the entire library (recommended for use in userscripts) ==== |
||
</div> |
|||
<syntaxhighlight lang="json"> |
<syntaxhighlight lang="json"> |
||
"ext.myExtension.foo": { |
"ext.myExtension.foo": { |
||
| Line 95: | Line 97: | ||
</syntaxhighlight> |
</syntaxhighlight> |
||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
==== Loading a subset of Codex components (recommended for skins and extensions) ==== |
==== Loading a subset of Codex components (recommended for skins and extensions) ==== |
||
</div> |
|||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
To only load a limited set of components, you can declare your dependencies in the following way below: |
|||
Declare the dependencies to only load a limited set of components; see section on [[#Advanced usage|advanced usage]]. |
|||
<syntaxhighlight lang="json"> |
|||
</div> |
|||
"ext.myExtension.foo": { |
|||
"class": "MediaWiki\\ResourceLoader\\CodexModule", |
|||
"packageFiles": [ |
|||
"init.js", |
|||
"MyComponent.vue" |
|||
], |
|||
"codexComponents": [ |
|||
"CdxButton", |
|||
"CdxCard", |
|||
"CdxDialog" |
|||
] |
|||
} |
|||
</syntaxhighlight> |
|||
This will generate a virtual file, <code>codex.js</code>, in your resources directory with the exports you need. |
|||
You can then require the components you requested from that virtual file: |
|||
<syntaxhighlight lang="js"> |
|||
// In resources/ext.myExtension.foo/MyComponent.vue |
|||
const { CdxButton, CdxTextInput } = require( '../codex.js' ); |
|||
</syntaxhighlight> |
|||
See the [[gitlab:repos/design-systems/CodexExample|CodexExample repository]] for more in-depth example of how to use Codex in a MediaWiki extension. |
|||
{{anchor|Using CSS-only Codex components}} |
{{anchor|Using CSS-only Codex components}} |
||
<span id="Usage_without_JavaScript_(CSS-only_Codex_components)"></span> |
<span id="Usage_without_JavaScript_(CSS-only_Codex_components)"></span> |
||
=== Utilizar sem o JavaScript (Componentes Codex apenas CSS) === |
=== Utilizar sem o JavaScript (Componentes Codex apenas CSS) === |
||
{{MW version |version=1.42 |comment=and after}} |
{{MW version |version=1.42 |comment=and after}} |
||
Many Codex components also support "CSS-only" usage. |
<span lang="en" dir="ltr" class="mw-content-ltr">Many Codex components also support "CSS-only" usage.</span> |
||
These components should appear visually identical to their JS-enabled counterparts, but they will offer more limited behavior. |
<span lang="en" dir="ltr" class="mw-content-ltr">These components should appear visually identical to their JS-enabled counterparts, but they will offer more limited behavior.</span> |
||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
===== Loading component styles ===== |
===== Loading component styles ===== |
||
</div> |
|||
<span lang="en" dir="ltr" class="mw-content-ltr">You can load the styles of a limited subset of Codex CSS components in the same way as you would for JS components, above.</span> |
|||
<span lang="en" dir="ltr" class="mw-content-ltr">If you only need the styles, you can add the <code>"codexStyleOnly": "true"</code> option when you define your module.</span> |
|||
You can load the styles of a limited subset of Codex CSS components in the same way as you would for JS components, above. |
|||
If you only need the styles, you can add the <code>"codexStyleOnly": "true"</code> option when you define your module. |
|||
<syntaxhighlight lang="json"> |
<syntaxhighlight lang="json"> |
||
"ext.myExtension.foo": { |
"ext.myExtension.foo": { |
||
| Line 149: | Line 132: | ||
</syntaxhighlight> |
</syntaxhighlight> |
||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
===== Providing component markup ===== |
===== Providing component markup ===== |
||
</div> |
|||
To use CSS-only Codex components, just ensure that the appropriate styles are loaded and then add the necessary markup to your page. |
<span lang="en" dir="ltr" class="mw-content-ltr">To use CSS-only Codex components, just ensure that the appropriate styles are loaded and then add the necessary markup to your page.</span> |
||
For now, you'll have to do this by hand. |
<span lang="en" dir="ltr" class="mw-content-ltr">For now, you'll have to do this by hand.</span> |
||
You can find example markup in the "CSS-only usage" section on a component's documentation page ([[wmdoc:codex/latest/components/demos/button.html#css-only-version|here is the markup for the Button component]]). |
<span lang="en" dir="ltr" class="mw-content-ltr">You can find example markup in the "CSS-only usage" section on a component's documentation page ([[wmdoc:codex/latest/components/demos/button.html#css-only-version|here is the markup for the Button component]]).</span> |
||
<syntaxhighlight lang="html"> |
<syntaxhighlight lang="html"> |
||
| Line 173: | Line 157: | ||
</syntaxhighlight> |
</syntaxhighlight> |
||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
=== Using Codex in PHP === |
=== Using Codex in PHP === |
||
</div> |
|||
{{Note |
|||
{{Note|type=warn|1=<span lang="en" dir="ltr" class="mw-content-ltr">Codex PHP is still under development and is not yet recommended for wide-spread use in [[Special:MyLanguage/Core|MediaWiki core]] ({{phab|399523}}).</span> <span lang="en" dir="ltr" class="mw-content-ltr">Breaking changes may be introduced until a stable version is released.</span>}} |
|||
| type = warn |
|||
| 1 = Codex PHP is still under development and is not yet recommended for wide-spread use in [[Special:MyLanguage/Core|MediaWiki core]] ({{phab|399523}}). Breaking changes may be introduced until a stable version is released. |
|||
}} |
|||
Codex PHP is a library for building CSS-only UI components using Codex, the Wikimedia design system, please see the [[wmdoc:design-codex-php/main/|Codex PHP documentation]]. |
|||
<span lang="en" dir="ltr" class="mw-content-ltr">Codex PHP is a library for building CSS-only UI components using Codex, the Wikimedia design system, please see the [[wmdoc:design-codex-php/main/|Codex PHP documentation]].</span> |
|||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
==== Installation ==== |
==== Installation ==== |
||
</div> |
|||
Install the Codex PHP library via {{ll|Composer}}: |
<span lang="en" dir="ltr" class="mw-content-ltr">Install the Codex PHP library via {{ll|Composer}}:</span> |
||
<syntaxhighlight lang="bash"> |
<syntaxhighlight lang="bash"> |
||
| Line 188: | Line 173: | ||
</syntaxhighlight> |
</syntaxhighlight> |
||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
==== Example usage ==== |
==== Example usage ==== |
||
</div> |
|||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
Here’s an example of creating an Accordion component in PHP: |
Here’s an example of creating an Accordion component in PHP: |
||
</div> |
|||
<syntaxhighlight lang="php"> |
<syntaxhighlight lang="php"> |
||
$accordion = $codex |
$accordion = $codex |
||
->accordion() |
->accordion() |
||
->setTitle( "Exemplo Acordeão" ) |
->setTitle( "Exemplo de Acordeão" ) |
||
->setDescription( "Este é um exemplo de um acordeão." ) |
->setDescription( "Este é um exemplo de um acordeão." ) |
||
->setContentHtml( |
->setContentHtml( |
||
$codex |
$codex |
||
->htmlSnippet() |
->htmlSnippet() |
||
->setContent( "<p> |
->setContent( "<p>Este é o conteúdo do acordeão.</p>" ) |
||
->build() |
->build() |
||
) |
) |
||
| Line 214: | Line 203: | ||
</syntaxhighlight> |
</syntaxhighlight> |
||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
== Advanced usage == |
== Advanced usage == |
||
</div> |
|||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
=== Using a limited subset of components === |
=== Using a limited subset of components === |
||
</div> |
|||
{{Note |
|||
{{Note|type=reminder|text=<span lang="en" dir="ltr" class="mw-content-ltr">Prioritize page load performance by using [[Special:MyLanguage/ResourceLoader|ResourceLoader]] to load only the necessary Codex components whenever possible.</span>}} |
|||
| type = reminder |
|||
<span lang="en" dir="ltr" class="mw-content-ltr">The <code>@wikimedia/codex</code> ResourceLoader module provides the entire Codex library – all components, styles, etc.</span> |
|||
| text = Prioritize page load performance by using [[Special:MyLanguage/ResourceLoader|ResourceLoader]] to load only the necessary Codex components whenever possible. |
|||
<span lang="en" dir="ltr" class="mw-content-ltr">If you are developing a skin or an extension and you care about performance, you should consider using Codex's '''code-splitting''' feature.</span> |
|||
}} |
|||
<span lang="en" dir="ltr" class="mw-content-ltr">ResourceLoader allows you to specify a list of Codex components and load only the JS/CSS for those components plus their dependencies by help of <code>CodexModule</code> class.</span> |
|||
The <code>@wikimedia/codex</code> ResourceLoader module provides the entire Codex library – all components, styles, etc. |
|||
{{Quote|text=<span lang="en" dir="ltr" class="mw-content-ltr">Registering many modules is highly discouraged, even if they are not loaded by default.</span> <span lang="en" dir="ltr" class="mw-content-ltr">The addition of each module adds 44{{nbsp}}bytes<ref>[[phab:T183720#9447986]]</ref> to every initial page load, so about 40{{nbsp}}GiB of extra transfer to Wikimedia servers per day.</span>|sign=[[Special:MyLanguage/ResourceLoader/Developing with ResourceLoader|ResourceLoader]]|source=}} |
|||
If you are developing a skin or an extension and you care about performance, you should consider using Codex's '''code-splitting''' feature. |
|||
ResourceLoader allows you to specify a list of Codex components and load only the JS/CSS for those components plus their dependencies. |
|||
{{Quote|text=Registering many modules is highly discouraged, even if they are not loaded by default. The addition of each module adds 44{{nbsp}}bytes<ref>[[phab:T183720#9447986]]</ref> to every initial page load, so about 40{{nbsp}}GiB of extra transfer to Wikimedia servers per day.|sign=[[Special:MyLanguage/ResourceLoader/Developing with ResourceLoader|ResourceLoader]]|source=}} |
|||
To use this feature, define a custom ResourceLoader module (this is typically done in <code>skin.json</code> or <code>extension.json</code>) and specify a list of <code>codexComponents</code>: |
<span lang="en" dir="ltr" class="mw-content-ltr">To use this feature, define a custom ResourceLoader module (this is typically done in <code>skin.json</code> or <code>extension.json</code>) and specify a list of <code>codexComponents</code>:</span> |
||
<syntaxhighlight lang="json"> |
<syntaxhighlight lang="json"> |
||
| Line 251: | Line 241: | ||
</syntaxhighlight> |
</syntaxhighlight> |
||
This will generate a virtual file, <code>codex.js</code>, in your <code>resources</code> directory with the exports you need. |
<span lang="en" dir="ltr" class="mw-content-ltr">This will generate a virtual file, <code>codex.js</code>, in your <code>resources</code> directory with the exports you need.</span> |
||
<span lang="en" dir="ltr" class="mw-content-ltr">You can then require the components and composables you requested from that virtual file:</span> |
<span lang="en" dir="ltr" class="mw-content-ltr">You can then require the components and composables you requested from that virtual file:</span> |
||
| Line 259: | Line 249: | ||
</syntaxhighlight> |
</syntaxhighlight> |
||
If you only need CSS-only components and don't wish to load the component JavaScript, you can add <code>"codexStyleOnly": true</code> to the module definition. |
<span lang="en" dir="ltr" class="mw-content-ltr">If you only need CSS-only components and don't wish to load the component JavaScript, you can add <code>"codexStyleOnly": true</code> to the module definition.</span> |
||
Similarly, if you only need the JavaScript files and not styles, you can add <code>"codexScriptOnly": "true"</code>. |
<span lang="en" dir="ltr" class="mw-content-ltr">Similarly, if you only need the JavaScript files and not styles, you can add <code>"codexScriptOnly": "true"</code>.</span> |
||
You should only do this if you're putting the styles in another, style-only module as described above. |
<span lang="en" dir="ltr" class="mw-content-ltr">You should only do this if you're putting the styles in another, style-only module as described above.</span> |
||
< |
<span lang="en" dir="ltr" class="mw-content-ltr">See the [[gitlab:repos/design-systems/CodexExample|CodexExample repository]] for more in-depth example of how to use Codex in a MediaWiki extension.</span> |
||
=== Using Codex icons === |
|||
</div> |
|||
<span id="Using_Codex_icons"></span> |
|||
=== Utilizar ícones do Codex === |
|||
<span lang="en" dir="ltr" class="mw-content-ltr">For performance reasons, there is no {{ll|ResourceLoader/Modules|ResourceLoader}} module named <code>{{del|codex-icons|}}</code> containing all the icons from Codex.</span> |
<span lang="en" dir="ltr" class="mw-content-ltr">For performance reasons, there is no {{ll|ResourceLoader/Modules|ResourceLoader}} module named <code>{{del|codex-icons|}}</code> containing all the icons from Codex.</span> |
||
<span lang="en" dir="ltr" class="mw-content-ltr">Such a module would be large and wasteful, since most users of Codex only need a handful of the 200+ icons.</span> |
<span lang="en" dir="ltr" class="mw-content-ltr">Such a module would be large and wasteful, since most users of Codex only need a handful of the 200+ icons.</span> |
||
| Line 284: | Line 276: | ||
</syntaxhighlight> |
</syntaxhighlight> |
||
Consulte também: |
|||
<span lang="en" dir="ltr" class="mw-content-ltr">See also:</span> |
|||
* [https://doc.wikimedia.org/codex/latest/icons/all-icons.html |
* [https://doc.wikimedia.org/codex/latest/icons/all-icons.html lista de todos os ícones (nome e variantes)] |
||
* [https://doc.wikimedia.org/codex/latest/using-codex/developing.html#using-icons |
* [https://doc.wikimedia.org/codex/latest/using-codex/developing.html#using-icons utilizar ícones em Vue] |
||
{{anchor|Codex design tokens|Using Codex design tokens in MediaWiki and extensions|Using Codex design tokens}} |
{{anchor|Codex design tokens|Using Codex design tokens in MediaWiki and extensions|Using Codex design tokens}} |
||
<span id="Using_design_tokens_directly"></span> |
|||
=== Utilizar códigos de desenho diretamente === |
|||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
=== Using design tokens directly === |
|||
</div> |
|||
<span lang="en" dir="ltr" class="mw-content-ltr">Design tokens can be imported into {{ll|Manual:Coding conventions/CSS|Less}} stylesheets as variables.</span> |
<span lang="en" dir="ltr" class="mw-content-ltr">Design tokens can be imported into {{ll|Manual:Coding conventions/CSS|Less}} stylesheets as variables.</span> |
||
<span lang="en" dir="ltr" class="mw-content-ltr">This may be useful if you are developing your own components or styles, and want them to integrate with Codex.</span> |
<span lang="en" dir="ltr" class="mw-content-ltr">This may be useful if you are developing your own components or styles, and want them to integrate with Codex.</span> |
||
| Line 309: | Line 299: | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
<div lang="en" dir="ltr" class="mw-content-ltr"> |
||
See the [[wmdoc:codex/latest/design-tokens/overview.html|full list of Codex's design tokens]], broken down by category. |
|||
</div> |
</div> |
||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
<div lang="en" dir="ltr" class="mw-content-ltr"> |
||
=== Codex |
=== Codex Less mixins === |
||
</div> |
</div> |
||
<span lang="en" dir="ltr" class="mw-content-ltr">Some Codex functionality is implemented using |
<span lang="en" dir="ltr" class="mw-content-ltr">Some Codex functionality is implemented using [https://lesscss.org/features/#mixins-feature Less mixins].</span> |
||
<span lang="en" dir="ltr" class="mw-content-ltr">For example, the [[wmdoc:codex/latest/components/mixins/link.html|Link component]] is a |
<span lang="en" dir="ltr" class="mw-content-ltr">For example, the [[wmdoc:codex/latest/components/mixins/link.html|Link component]] is a Less mixin rather than a Vue component, and using icons in CSS-only components requires using a Less mixin (see also the documentation for [[#Using CSS-only Codex components|using CSS-only components]]).</span> |
||
<span lang="en" dir="ltr" class="mw-content-ltr">Using Codex |
<span lang="en" dir="ltr" class="mw-content-ltr">Using Codex Less mixins in MediaWiki and extensions works very similarly to [[#Using Codex design tokens in MediaWiki and extensions|using design tokens]]: simply import <code>mediawiki.skin.variables.less</code>, which makes all Codex mixins available, as well as the design tokens.</span> |
||
<syntaxhighlight lang="less"> |
<syntaxhighlight lang="less"> |
||
| Line 330: | Line 320: | ||
</syntaxhighlight> |
</syntaxhighlight> |
||
<span id="Using_Codex_in_userscripts"></span> |
|||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
=== |
=== Utilizar Codex em ''scripts'' do utilizador === |
||
<span lang="en" dir="ltr" class="mw-content-ltr">It is possible to use Codex in userscripts.</span> |
|||
</div> |
|||
<span lang="en" dir="ltr" class="mw-content-ltr">However, there are some limitations that will require certain workarounds.</span> |
|||
< |
<span lang="en" dir="ltr" class="mw-content-ltr">Here are a few considerations to keep in mind when using Vue and Codex in userscripts:</span> |
||
It is possible to use Codex in userscripts. |
|||
However, there are some limitations that will require certain workarounds. |
|||
Here are a few considerations to keep in mind when using Vue and Codex in userscripts: |
|||
</div> |
|||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
<div lang="en" dir="ltr" class="mw-content-ltr"> |
||
| Line 347: | Line 333: | ||
</div> |
</div> |
||
<span id="Loading_Vue/Codex"></span> |
|||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
==== |
==== Carregar Vue/Codex ==== |
||
<span lang="en" dir="ltr" class="mw-content-ltr">You'll need to load Vue and Codex from ResourceLoader.</span> |
|||
</div> |
|||
<span lang="en" dir="ltr" class="mw-content-ltr">The best way to do this is via <code>mw.loader.using</code>; the rest of your userscript code should live in a callback or promise chain.</span> |
|||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
You'll need to load Vue and Codex from ResourceLoader. |
|||
The best way to do this is via <code>mw.loader.using</code>; the rest of your userscript code should live in a callback or promise chain. |
|||
</div> |
|||
<syntaxhighlight lang="js"> |
<syntaxhighlight lang="js"> |
||
| Line 363: | Line 345: | ||
</syntaxhighlight> |
</syntaxhighlight> |
||
<span id="Use_Vue.createMwApp"></span> |
|||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
==== |
==== Utilizar <code>Vue.createMwApp</code> ==== |
||
<span lang="en" dir="ltr" class="mw-content-ltr">Once you've loaded Vue and Codex, you must define a Vue app and mount it somewhere on the page.</span> |
|||
</div> |
|||
<span lang="en" dir="ltr" class="mw-content-ltr">The exact location will vary depending on what you are trying to do.</span> |
|||
< |
<span lang="en" dir="ltr" class="mw-content-ltr">You can use [https://github.com/wikimedia/mediawiki/blob/master/resources/src/vue/index.js MediaWiki's custom <code>createMwApp</code> method] for this.</span> |
||
Once you've loaded Vue and Codex, you must define a Vue app and mount it somewhere on the page. |
|||
The exact location will vary depending on what you are trying to do. |
|||
You can use [https://github.com/wikimedia/mediawiki/blob/master/resources/src/vue/index.js MediaWiki's custom <code>createMwApp</code> method] for this. |
|||
</div> |
|||
<syntaxhighlight lang="js"> |
<syntaxhighlight lang="js"> |
||
mw.loader.using( '@wikimedia/codex' ).then( function( require ) { |
mw.loader.using( '@wikimedia/codex' ).then( function( require ) { |
||
//... require Vue and Codex as above |
//... require Vue and Codex as above. |
||
// |
// Create an element to mount the Vue app. |
||
const mountPoint = document.body.appendChild( document.createElement( 'div' ) ); |
const mountPoint = document.body.appendChild( document.createElement( 'div' ) ); |
||
// |
// Create a Vue app and mount it to the target element. |
||
Vue.createMwApp( { |
Vue.createMwApp( { |
||
// data, computed props, methods, etc. go here |
// data, computed props, methods, etc. go here. |
||
} ).mount( mountPoint ); |
} ).mount( mountPoint ); |
||
} ); |
} ); |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
<span id="Real_examples"></span> |
|||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
==== |
==== Exemplos reais ==== |
||
</div> |
|||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
<div lang="en" dir="ltr" class="mw-content-ltr"> |
||
| Line 394: | Line 371: | ||
</div> |
</div> |
||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
https://en.wikipedia.org/wiki/User:EGardner_(WMF)/codex-hello-world.js |
https://en.wikipedia.org/wiki/User:EGardner_(WMF)/codex-hello-world.js |
||
</div> |
|||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
<div lang="en" dir="ltr" class="mw-content-ltr"> |
||
| Line 402: | Line 377: | ||
</div> |
</div> |
||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
https://en.wikipedia.org/wiki/User:JSherman_(WMF)/revertrisk.js |
https://en.wikipedia.org/wiki/User:JSherman_(WMF)/revertrisk.js |
||
</div> |
|||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
<div lang="en" dir="ltr" class="mw-content-ltr"> |
||
== Release cycle == |
== Release cycle == |
||
A new version of Codex is released every other Tuesday. |
|||
When a new release is created, a patch is also submitted to MediaWiki core to use that new release. |
|||
Since this is done on Tuesdays, the update to core will be deployed the following week (the next time the [https://wikitech.wikimedia.org/wiki/Deployments/Train deployment train runs]). |
|||
</div> |
</div> |
||
<span lang="en" dir="ltr" class="mw-content-ltr">New versions of Codex are released ad hoc as needed, not on a specific schedule.</span> |
|||
<span lang="en" dir="ltr" class="mw-content-ltr">When a new release is created, a patch is also submitted to MediaWiki core to use that new release.</span> |
|||
<span lang="en" dir="ltr" class="mw-content-ltr">Since this is typically done on Tuesdays, the update to core will be deployed the following week (the next time the [https://wikitech.wikimedia.org/wiki/Deployments/Train deployment train runs]).</span> |
|||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
<div lang="en" dir="ltr" class="mw-content-ltr"> |
||
== Using a custom version of Codex for development or testing == |
== Using a custom version of Codex for development or testing == |
||
MediaWiki uses the latest release of Codex. If you need to use a different version for development or testing purposes, for example to test how an unmerged patch in Codex interacts with MediaWiki, you can point MediaWiki to your own version of Codex as follows: |
|||
</div> |
</div> |
||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
<div lang="en" dir="ltr" class="mw-content-ltr"> |
||
MediaWiki uses the latest release of Codex. If you need to use a different version for development or testing purposes, for example to test how an unmerged patch in Codex interacts with MediaWiki, you can point MediaWiki to your own version of Codex as follows: |
|||
# Clone the [[git:design/codex|Codex repository]] (if you haven't already), and check out the change you want to test. |
|||
# Run <code>npm install</code> and <code>npm run build-all</code> in the root directory of the Codex repository. |
|||
# Point <code>$wgCodexDevelopmentDir</code> to the root directory of the Codex repository. For example, if you cloned the Codex repository in the parent directory of the MediaWiki directory, add <code>$wgCodexDevelopmentDir = MW_INSTALL_PATH . '../codex';</code> to <code>LocalSettings.php</code> |
|||
# Test that it works by running <code>mw.loader.load( '@wikimedia/codex' )</code> in the browser console. This should trigger a warning saying "You are using a local development version of Codex", and should not trigger any errors. |
|||
</div> |
</div> |
||
# <span lang="en" dir="ltr" class="mw-content-ltr">Clone the [[git:design/codex|Codex repository]] (if you haven't already), and check out the change you want to test.</span> |
|||
# <span lang="en" dir="ltr" class="mw-content-ltr">Run <code>npm install</code> and <code>npm run build-all</code> in the root directory of the Codex repository.</span> |
|||
# <span lang="en" dir="ltr" class="mw-content-ltr">Point <code>$wgCodexDevelopmentDir</code> to the root directory of the Codex repository. For example, if you cloned the Codex repository in the parent directory of the MediaWiki directory, add <code>$wgCodexDevelopmentDir = MW_INSTALL_PATH . '../codex';</code> to <code>LocalSettings.php</code></span> |
|||
# <span lang="en" dir="ltr" class="mw-content-ltr">Test that it works by running <code>mw.loader.load( '@wikimedia/codex' )</code> in the browser console. This should trigger a warning saying "You are using a local development version of Codex", and should not trigger any errors.</span> |
|||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
<div lang="en" dir="ltr" class="mw-content-ltr"> |
||
| Line 433: | Line 407: | ||
</div> |
</div> |
||
<span id="Notes"></span> |
|||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
== |
== Notas == |
||
</div> |
|||
<references /> |
<references /> |
||
Latest revision as of 21:16, 8 August 2026
|
Codex
Sistema de desenho para a Wikimédia com linhas diretrizes e um conjunto de ferramentas (códigos de desenho, componentes, e ícones) para criar interfaces do utilizador
|
Codex é o sistema de desenho oficial para a Wikimedia. Este fornece um conjunto unificado de ferramentas, linhas diretrizes, e componentes para ajudar os programadores e desenhadores a criarem interfaces do utilizador consistentes, acessíveis e localizadas nos projetos da Wikimédia.
Codex enables contributors to use standardized UI components built with Vue.js or plain CSS—such as buttons, menus, dialogs, and icons. It ensures a consistent look and behavior for our products, so that they align with the visual style and functionality standards of Wikimedia. It supports both developers and designers in creating user-friendly and maintainable interfaces.
Visite o site da documentação oficial para detalhes completos do Codex, incluindo como o utilizar fora do MediaWiki.
Codex é o sistema recomendado de desenho da interface do utilizador, e foi incorporado no MediaWiki desde MediaWiki 1.39. It is also available as a set of npm packages. The system is collaboratively developed by the Wikimedia Foundation, Wikimedia Deutschland, and volunteer contributors.
Codex's source code is hosted on Gerrit, and its development is tracked in Phabricator. Visit the full changelog and join our Contributor Telegram group to get involved.
Utilização básica
Codex provides a variety of components which skin, extension, and userscript authors can embed in their own user interfaces: buttons, checkboxes, toggle switches, dialogs, etc. Many of these components can be extensively customized.
CodexExample MediaWiki extension
The Codex/Steering Committee maintains the CodexExample MediaWiki extension that demonstrates how to use design tokens, components, and icons from Codex.
This extension can be installed (it sets up a dedicated special page called Special:CodexExample with live demos), or you can study its source code for inspiration.
See the project README.md page for more information on installation and use.
Usage with JavaScript
Codex components are built using the Vue.js JavaScript framework.
If you are developing a Vue application in MediaWiki, then it's easy to load Codex components from ResourceLoader using require().
You can load all of Codex at once, or just a limited subset of components.
Loading the entire library (recommended for use in userscripts)
"ext.myExtension.foo": {
"dependencies": [ "@wikimedia/codex" ]
"packageFiles": [
"init.js",
"MyComponent.vue"
]
}
<!-- MyComponent.vue -->
<template>
<cdx-button @click="doSomething">Clique-me!</cdx-button>
</template>
<script>
const { CdxButton } = require( '@wikimedia/codex' );
module.exports = exports = {
name: "MyComponent",
components: {
CdxButton
},
methods: {
doSomething() {
//...
}
}
}
</script>
Loading a subset of Codex components (recommended for skins and extensions)
Declare the dependencies to only load a limited set of components; see section on advanced usage.
Utilizar sem o JavaScript (Componentes Codex apenas CSS)
| Versão MediaWiki: | ≥ 1.42 |
Many Codex components also support "CSS-only" usage. These components should appear visually identical to their JS-enabled counterparts, but they will offer more limited behavior.
Loading component styles
You can load the styles of a limited subset of Codex CSS components in the same way as you would for JS components, above.
If you only need the styles, you can add the "codexStyleOnly": "true" option when you define your module.
"ext.myExtension.foo": {
"class": "MediaWiki\\ResourceLoader\\CodexModule",
"styles": "ext.myExtension.foo/styles.less",
"codexStyleOnly": "true",
"codexComponents": [
"CdxButton",
"CdxCard",
"CdxCheckbox",
"CdxProgressBar"
]
}
Providing component markup
To use CSS-only Codex components, just ensure that the appropriate styles are loaded and then add the necessary markup to your page. For now, you'll have to do this by hand. You can find example markup in the "CSS-only usage" section on a component's documentation page (here is the markup for the Button component).
<div>
<button class="cdx-button cdx-button--action-default">
Botão predefinido
</button>
</div>
<div>
<button class="cdx-button cdx-button--action-progressive">
Botão progressivo
</button>
</div>
<div>
<button class="cdx-button cdx-button--action-destructive">
Botão destrutivo
</button>
</div>
Using Codex in PHP
Codex PHP is a library for building CSS-only UI components using Codex, the Wikimedia design system, please see the Codex PHP documentation.
Installation
Install the Codex PHP library via Composer:
composer require wikimedia/codex
Example usage
Here’s an example of creating an Accordion component in PHP:
$accordion = $codex
->accordion()
->setTitle( "Exemplo de Acordeão" )
->setDescription( "Este é um exemplo de um acordeão." )
->setContentHtml(
$codex
->htmlSnippet()
->setContent( "<p>Este é o conteúdo do acordeão.</p>" )
->build()
)
->setOpen( false )
->setAttributes( [
"class" => "foo",
"bar" => "baz",
] )
->build()
->getHtml();
echo $accordion;
Advanced usage
Using a limited subset of components
The @wikimedia/codex ResourceLoader module provides the entire Codex library – all components, styles, etc.
If you are developing a skin or an extension and you care about performance, you should consider using Codex's code-splitting feature.
ResourceLoader allows you to specify a list of Codex components and load only the JS/CSS for those components plus their dependencies by help of CodexModule class.
Registering many modules is highly discouraged, even if they are not loaded by default. The addition of each module adds 44 bytes[1] to every initial page load, so about 40 GiB of extra transfer to Wikimedia servers per day.
To use this feature, define a custom ResourceLoader module (this is typically done in skin.json or extension.json) and specify a list of codexComponents:
"ext.myExtension.blockform": {
"class": "MediaWiki\\ResourceLoader\\CodexModule",
"codexComponents": [
"CdxButton",
"CdxCard",
"CdxDialog",
"CdxIcon",
"CdxRadio",
"CdxTextInput",
"useModelWrapper"
],
"packageFiles": [
"init.js",
"BlockForm.vue"
],
"messages": [
"block-target",
"ipb-submit"
]
}
This will generate a virtual file, codex.js, in your resources directory with the exports you need.
You can then require the components and composables you requested from that virtual file:
// In resources/ext.myExtension/BlockForm.vue
const { CdxButton, CdxTextInput } = require( '../codex.js' );
If you only need CSS-only components and don't wish to load the component JavaScript, you can add "codexStyleOnly": true to the module definition.
Similarly, if you only need the JavaScript files and not styles, you can add "codexScriptOnly": "true".
You should only do this if you're putting the styles in another, style-only module as described above.
See the CodexExample repository for more in-depth example of how to use Codex in a MediaWiki extension.
Utilizar ícones do Codex
For performance reasons, there is no ResourceLoader module named containing all the icons from Codex.
Such a module would be large and wasteful, since most users of Codex only need a handful of the 200+ icons.
Instead, ResourceLoader provides a way for modules to embed the icons they need, similar to the code-splitting approach described above.
codex-icons
{
"name": "icons.json",
"callback": "MediaWiki\\ResourceLoader\\CodexModule::getIcons",
"callbackParam": [
// List the icons your module needs here, e.g.:
"cdxIconArrowNext",
"cdxIconBold",
"cdxIconTrash"
]
}
Consulte também:
Utilizar códigos de desenho diretamente
Design tokens can be imported into Less stylesheets as variables. This may be useful if you are developing your own components or styles, and want them to integrate with Codex.
Codex design tokens should be imported from the mediawiki.skin.variables.less file.
@import 'mediawiki.skin.variables.less';
.my-feature {
background-color: @background-color-base;
color: @color-base;
}
See the full list of Codex's design tokens, broken down by category.
Codex Less mixins
Some Codex functionality is implemented using Less mixins. For example, the Link component is a Less mixin rather than a Vue component, and using icons in CSS-only components requires using a Less mixin (see also the documentation for using CSS-only components).
Using Codex Less mixins in MediaWiki and extensions works very similarly to using design tokens: simply import mediawiki.skin.variables.less, which makes all Codex mixins available, as well as the design tokens.
@import 'mediawiki.skin.variables.less';
.my-feature {
a {
.cdx-mixin-link-base();
}
}
Utilizar Codex em scripts do utilizador
It is possible to use Codex in userscripts. However, there are some limitations that will require certain workarounds. Here are a few considerations to keep in mind when using Vue and Codex in userscripts:
- No
.vuesingle-file component support; you must define components in plain.jsfiles - Everything needs to live in one file; userscripts don't provide a good way to load custom modules
- Define component templates using ES6 template literals
- Prefer global component registration for Codex components
Carregar Vue/Codex
You'll need to load Vue and Codex from ResourceLoader.
The best way to do this is via mw.loader.using; the rest of your userscript code should live in a callback or promise chain.
mw.loader.using( '@wikimedia/codex' ).then( function( require ) {
const Vue = require( 'vue' );
const Codex = require( '@wikimedia/codex' );
} );
Utilizar Vue.createMwApp
Once you've loaded Vue and Codex, you must define a Vue app and mount it somewhere on the page.
The exact location will vary depending on what you are trying to do.
You can use MediaWiki's custom createMwApp method for this.
mw.loader.using( '@wikimedia/codex' ).then( function( require ) {
//... require Vue and Codex as above.
// Create an element to mount the Vue app.
const mountPoint = document.body.appendChild( document.createElement( 'div' ) );
// Create a Vue app and mount it to the target element.
Vue.createMwApp( {
// data, computed props, methods, etc. go here.
} ).mount( mountPoint );
} );
Exemplos reais
The link below shows a complete example of a userscript which adds a portlet link to all Wiki pages that triggers a custom Codex Dialog component to launch when clicked. Feel free to copy this script to your own user page to use as a starting point.
https://en.wikipedia.org/wiki/User:EGardner_(WMF)/codex-hello-world.js
Here is another script using Codex :
https://en.wikipedia.org/wiki/User:JSherman_(WMF)/revertrisk.js
Release cycle
New versions of Codex are released ad hoc as needed, not on a specific schedule. When a new release is created, a patch is also submitted to MediaWiki core to use that new release. Since this is typically done on Tuesdays, the update to core will be deployed the following week (the next time the deployment train runs).
Using a custom version of Codex for development or testing
MediaWiki uses the latest release of Codex. If you need to use a different version for development or testing purposes, for example to test how an unmerged patch in Codex interacts with MediaWiki, you can point MediaWiki to your own version of Codex as follows:
- Clone the Codex repository (if you haven't already), and check out the change you want to test.
- Run
npm installandnpm run build-allin the root directory of the Codex repository. - Point
$wgCodexDevelopmentDirto the root directory of the Codex repository. For example, if you cloned the Codex repository in the parent directory of the MediaWiki directory, add$wgCodexDevelopmentDir = MW_INSTALL_PATH . '../codex';toLocalSettings.php - Test that it works by running
mw.loader.load( '@wikimedia/codex' )in the browser console. This should trigger a warning saying "You are using a local development version of Codex", and should not trigger any errors.
Once you have this set up, you can make additional changes to your Codex clone, but you have to run npm run build-all each time to make those changes take effect in MediaWiki.
To disable development mode and go back to using the latest release of Codex, comment out the line in LocalSettings.php that sets $wgCodexDevelopmentDir.
