| .. | ||
| app/controllers/styleguide | ||
| assets | ||
| config | ||
| db/migrate | ||
| lib/styleguide | ||
| public/images | ||
| spec | ||
| package.json | ||
| plugin.rb | ||
| README.md | ||
| screenshot.png | ||
| tsconfig.json | ||
styleguide
Adds a URL of /styleguide to discourse that renders widgets in various
configurations to aid in styling.
Code examples
Discourse's build pipeline allows adding ?source=file or ?source=template to
a module import. This provides a string of the raw source code for the entire
file, or just for the <template>. Put the example in its own module under
examples/, import it twice, and pass the string to @code:
import StyleguideExample from "discourse/plugins/styleguide/discourse/components/styleguide-example";
import CharCounterExample from "../../examples/molecules/char-counter";
import charCounterSource from "../../examples/molecules/char-counter?source=file";
export default <template>
<StyleguideExample @title="<DCharCounter>" @code={{charCounterSource}}>
<CharCounterExample />
</StyleguideExample>
</template>
The import must resolve within the same plugin or theme bundle, and
?source=template requires the module to contain exactly one <template>.
Criteria
Samples typed by hand drift from the code they describe. These rules keep that from being possible.
-
Every
<StyleguideExample>that passes@codepasses a?source=import, never a hand-written string. -
Each example is its own module under
examples/. A module may back several examples when the variants differ only in the data passed in. -
Use
?source=filewhen the module has imports or JS, so the reader sees what to paste into a new file. Use?source=templatewhen it is pure markup. -
The example module holds only the API being taught. Styleguide-only chrome stays in the section file, wrapping the example.
-
An example receives only what it cannot build itself. Store-backed records come in as named args; literal fixtures, state and callbacks the example owns. Examples never take
@dummyitself. -
An example demonstrating a design token, a color or a type scale does not need
@codeat all. -
A hand-written
@codestring is admissible only when the sample cannot be a module that renders on this page: it is computed from the page's live controls, or the block is a gallery rather than a usage example. It must carry a comment saying which.
Layout
examples/<group>/<section>/<name>.gjs
<group> is atoms, molecules or organisms; <section> is the section
file name without its numeric prefix; <name> is a kebab-case slug for the
variant. Import with a relative specifier and no file extension, and name the
bindings <Name>Example and <name>Source.
