learningequality / kolibri-design-system

Kolibri Design System
https://design-system.learningequality.org
30 stars 73 forks source link

Create a new documentation component `DocsExample` that allows to toggle between an example and its code #826

Open MisRob opened 11 hours ago

MisRob commented 11 hours ago

🌱 Are you new to the codebase? Welcome! Please see the contributing guidelines.

Desired behavior

Create a new documentation component DocsExample that toggles between an example and its code on the documentation website.

<DocsExample language="html">
  <template #example>
    // Renders the example
  </template>
  <template #code>
    // Renders the source code
  </template>
</DocsExample>

Here is one example demonstrating the expected visual output. For this KCard demonstration (source, output)

<DocsExample language="html">
  <template #example>
    <KCardGrid ...>
         ...
    </KCardGrid>
  </template>
  <template #code>
    <KCardGrid ...>
      ...
    </KCardGrid>
  </template>
</DocsExample>

should produce the following:

(1) On an initial page load, we'd only show the card passed via the #example slot

(2) The code sample related to the example would be passed via the #code slot

(3) DocsExample would render a toggle button to "View code"/"Hide code" in its top right corner. Clicking it would show/hide the code above the card:

The overall experience would be similar to that of the Vuetify documentation:

Current behavior

Right now we show code above or below the example, or not at all, and there is no way to toggle it:

The Value Add

Guidance

Out of scope

At this stage, we only want to focus on creating DocsExample . Please do not refactor all examples on all website pages with it.

Acceptance criteria

MisRob commented 10 hours ago

Labeling as "good first issue" since its pretty straightforward and can be tested easily, but note that it's medium size. Furthermore, if it's your first encounter with the documentation website, some time will be needed to understand the current documentation mechanism well.