-
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
11 changed files
with
341 additions
and
107 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 documentations frequently need to add interactive examples next to code snippets showcasing how you would get to build that. | ||
|
||
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 checked as 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. |
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
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.