-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow dynamically loaded example files
- Loading branch information
Showing
12 changed files
with
422 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Adding code examples | ||
|
||
Component library documentation frequently needs to show interactive examples, along with the code for them. | ||
|
||
Manually writing those code snippets has some issues: they are not covered by your type checking and linting tasks, and they can accidentally get outdated. | ||
|
||
The web-based documentation included with this library allows to create example files which are both used as regular modules that can be imported for interactive examples, but also read as plain text to generate their corresponding code snippet. | ||
|
||
These files are type-checked, formatted and linted like any other source files, and the code snippet will always be in sync with the interactive example. | ||
|
||
## Using example files | ||
|
||
When you want to create a code example, add a file with the name of your choice inside `src/pattern-library/examples` directory. | ||
|
||
You can then reference this file from the web-based pattern library, passing the `exampleFile` prop to the `<Library.Demo />` component. | ||
|
||
```tsx | ||
<Library.Demo exampleFile="some-example-file-name" /> | ||
``` | ||
|
||
## Considerations | ||
|
||
There are some considerations and limitations when working with example files. | ||
|
||
- They all need to have the `tsx` extension. | ||
- Nested directories are not supported, so it's a good idea to add contextual prefixes to example files. For example, all files related with `SelectNext` can be prefixed with `select-next` to make sure they are all grouped together. | ||
- Example files need to have a Preact component as their default export. | ||
- When generating the source code snippet, import statements are stripped out, to avoid internal module references which are not relevant for the library consumers. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.