Page MenuHomePhabricator

docs: Document component Less mixins
Closed, ResolvedPublic1 Estimated Story Points

Description

Summary

With T314332, we decided to support certain standard visual styles via Less mixins. Some of these mixins, such as Link (T316895), are effectively components that only require shared Less mixins rather than a JavaScript implementation. We should consider how to document component mixins like Link on the docs site, then implement this new infrastructure.

Implementation

Considerations

  • We should consider how users of the Codex site will look for components that they want to learn about or use, and organize things in an intuitive and clear way
  • In addition to components that are only implemented as Less mixins, we may eventually have components (like Button and some inputs) that are implemented both ways. We should keep this in mind as we develop the architecture for standalone mixins.
  • The current component docs infrastructure relies on vue-docgen-cli and a custom script that runs vue-docgen-cli, pulls from the manually-created component demos, and puts everything on a single page in a standard order
  • The current design tokens demos are all manually constructed and use various Vue components for standard layouts
  • We will need to build out infrastructure for displaying a page for each mixin or a single page with all mixins

Options

Location of component mixin demo pages

Option 1: Include demo pages for component mixins alongside Vue component demo pages

This option would not separate Vue components from mixins, but would place mixins where they logically belong alongside components. This would be further supported when we implement component groupings, which will aim to group components by what they do (rather than what they are or how they're implemented).

For components that are implemented both as a Vue component and a Less mixin, we could document both versions on a single demo page.

Option 2: Include demo pages for component mixins as a separate section, distinct from components

Alternately, we could have a separate section on the docs site for mixins. This would mean changing the site architecture to create a place for mixins, and would mean documenting components implemented both as a Vue component and a less mixin in two separate places.

Infrastructure for component mixin demo pages

These options apply to the first solution for location above (alongside Vue components).

Option 1: Copy mixin demo pages into docs/components/demos

Process:

  • As component demos are set up in packages/codex-docs/component-demos, so mixin demos will be set up in packages/codex-docs/mixin-demos
  • These mixin demos will take a similar form as the component ones, a markdown file explaining the mixin and providing examples as Vue components
  • We write a script that copies all files matching the pattern mixin-demos/[mixin-name]/[mixin-name].md into docs/components/demos at the end of the docgen:build script

Upside: component mixins live alongside components and have the same path
Downside: no HMR out of the box; we'd have to write a script to watch these files for changes and copy them over when they do

Option 2: Static mixin files in a separate directory

Process:

  • We set up docs/components/mixins as a directory for static mixin demo pages
  • We either list them in a separate section in the sidebar, or mix them into the list of components

Upside: HMR, extremely easy
Downside: mixin demo pages have a different path than component demo pages


Acceptance criteria

  • Choose an implementation path
  • Implement the necessary infrastructure, using the Link component as an example
  • Include general instructions on using these mixins

Event Timeline

I'd recommend we go with option 1, and include component mixins along with Vue components in the docs.

I think this would:

  • Be more intuitive
  • Keep the docs site architecture simpler
  • Better support the case of components implemented as both a Vue component and a Less mixin

To execute this, we'll need to do something like this:

  • Update the docgen script to copy all markdown files like packages/codex-docs/components-demos/[component-name]/[component-name].mdover to packages/codex-docs/docs/components/[component-name].md. Right now, it only does this for files that have an associated Vue SFC in the codex package.
  • Add packages/codex-docs/component-demos/link/link.md with an explanation and examples
  • Consider adding a standard "tip" to emphasize that a component either is only represented by a Less mixin, or contains both a Vue and a Less implementation
  • Consider adding a script that pulls the docblock of a component mixin into the markdown file, similar to what vue-docgen-cli does with Vue files
  • Consider adding a script that pulls in and documents the actual mixins, similar to what vue-docgen-cli does with component methods
Catrope triaged this task as High priority.Sep 12 2022, 8:27 AM
Catrope moved this task from Inbox to Up Next on the Design-System-Team board.
AnneT set the point value for this task to 1.Sep 12 2022, 6:55 PM

This estimate is for the simplest approach – manually creating pages for mixins where necessary.

We can examine an automated process later if that is necesary.

This task is blocked by T317235: Add "Overview" to components section – once that task is complete, it should be possible to create additional custom pages alongside component docs (which are auto-generated from Vue files).

egardner changed the task status from Open to Stalled.Sep 12 2022, 6:58 PM
egardner moved this task from Up Next to Design-System-Sprint on the Design-System-Team board.
AnneT renamed this task from docs: Document component mixins to docs: Document component Less mixins.Oct 24 2022, 4:30 PM
AnneT updated the task description. (Show Details)

Change 849176 had a related patch set uploaded (by Anne Tomasevich; author: Anne Tomasevich):

[design/codex@main] docs, Link: Add page for the Link mixin

https://gerrit.wikimedia.org/r/849176

This task is blocked by T321354: we need to have a better idea how we'll implement CSS-only components before we can determine how to document component Less mixins. We need to determine:

  1. If we'll document components that are only implemented as Less mixins in the same way as components that have both a Vue and a CSS/Less implementation
  2. If we'll document each of those things alongside Vue components or in a separate section

That said, to unblock design review of Link, I have pushed a patch to add a temporary page for the Link mixin. Most of this code should be reusable once we determine the final architecture.

Change 849176 merged by jenkins-bot:

[design/codex@main] docs, Link: Add page for the Link mixin

https://gerrit.wikimedia.org/r/849176

Change 859597 had a related patch set uploaded (by Anne Tomasevich; author: Anne Tomasevich):

[mediawiki/core@master] Update Codex from v0.2.2 to v0.3.0

https://gerrit.wikimedia.org/r/859597

Change 859597 merged by jenkins-bot:

[mediawiki/core@master] Update Codex from v0.2.2 to v0.3.0

https://gerrit.wikimedia.org/r/859597

We've gone ahead and followed Option 1 for the Link component mixin: https://doc.wikimedia.org/codex/main/components/mixins/link.html

This issue will come up again in the context of CSS components, but we can handle as a sub-task of the larger epic.