-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
75f3209
commit af05061
Showing
9 changed files
with
171 additions
and
3 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,12 @@ | ||
--- | ||
id: about | ||
title: Lookbook Demo | ||
--- | ||
|
||
**This is a demo of Lookbook, a _ready-to-go_ component development UI for [ViewComponent](http://viewcomponent.org/)-based projects.** | ||
|
||
It uses (and extends) the native [ViewComponent preview functionality](https://viewcomponent.org/guide/previews.html), so you don't need to learn a new DSL or create any extra files to get up and running. | ||
|
||
Lookbook uses [RDoc/Yard-style comment tags](<%= page_path :annotations %>) to extend the capabilities of ViewComponent's previews whilst maintaining compatability with the standard preview class format, so you can add or remove Lookbook at any time without having to rework your code. | ||
|
||
<%= image_tag "lookbook_screenshot.png" %> |
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,86 @@ | ||
--- | ||
id: annotations | ||
title: Annotating preview files | ||
--- | ||
|
||
Lookbook parses [Yard-style comment tags](https://rubydoc.info/gems/yard/file/docs/Tags.md) in your preview class files to customise and extend the standard ViewComponent preview experience. | ||
|
||
**Tags** are just strings identified by their `@` prefix - for example `@hidden`. Tags are always placed in a comment above the relevant preview class or example method. | ||
|
||
## Example preview file: | ||
|
||
```ruby | ||
# @label Basic Button | ||
# @display bg_color "#fff" | ||
class ButtonComponentPreview < ViewComponent::Preview | ||
|
||
# Primary button | ||
# --------------- | ||
# This is the button style you should use for most things. | ||
# | ||
# @label Primary | ||
def default | ||
render ButtonComponent.new do | ||
"Click me" | ||
end | ||
end | ||
|
||
# Button with icon | ||
# ---------------- | ||
# This example uses dynamic preview parameters | ||
# which can be edited live in the Lookbook UI | ||
# | ||
# @param text | ||
# @param icon select [heart, cog, alert] | ||
def icon(text: "Spread the love", icon: "heart") | ||
render ButtonComponent.new(icon: icon) do | ||
text | ||
end | ||
end | ||
|
||
# Inverted button | ||
# --------------- | ||
# For light-on-dark screens | ||
# | ||
# @display bg_color "#000" | ||
def secondary | ||
render ButtonComponent.new(style: :inverted) do | ||
"Click me" | ||
end | ||
end | ||
|
||
# Unicorn button | ||
# --------------- | ||
# This button style is still a **work in progress**. | ||
# | ||
# @hidden | ||
def secondary | ||
render ButtonComponent.new do | ||
"Click me" | ||
end | ||
end | ||
|
||
# @!group More examples | ||
|
||
def short_text | ||
render ButtonComponent.new do | ||
"Go" | ||
end | ||
end | ||
|
||
def long_text | ||
render ButtonComponent.new do | ||
"Click here to do this thing because it's the best way to do it" | ||
end | ||
end | ||
|
||
def emoji_text | ||
render ButtonComponent.new do | ||
"👀📗" | ||
end | ||
end | ||
|
||
# @!endgroup | ||
|
||
end | ||
``` |
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,35 @@ | ||
--- | ||
title: Pages Overview | ||
--- | ||
|
||
If you need to add more long-form documentation to live alongside your component previews you can do so using Lookbook's markdown-powered `pages` system. | ||
|
||
**The documentation you are reading right now** is an example what pages look like when they are rendered. | ||
|
||
## Usage | ||
|
||
By default, pages should be placed in the `test/components/docs` directory (although this can be customised) and can be nested in directories as deeply as required. | ||
|
||
Pages must have either a `.html.erb` or a `.md.erb` file extension. All pages are rendered as ERB templates but `.md.erb` files will also additionally be run through a markdown parser. | ||
|
||
Pages can optionally make use of a **YAML frontmatter block** to customise the behaviour and content of the page itself. | ||
|
||
An example page might look like this: | ||
|
||
```markdown | ||
--- | ||
title: An example page | ||
label: Nice example | ||
--- | ||
|
||
This is an example page. If it has a `.md.erb` file extension its | ||
contents will be run through a Markdown parser/renderer before display. | ||
|
||
Fenced code blocks are fully supported and will be highlighted appropriately. | ||
|
||
ERB can be used in here. | ||
The template will be rendered **before** being parsed as Markdown. | ||
|
||
You can can access data about the page using the `@page` variable. | ||
The title of this page is ">%= @page.title %<". | ||
``` |
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,26 @@ | ||
--- | ||
label: Embedding Previews | ||
--- | ||
|
||
You can embed preview examples from your project directly into the documentation pages using the `embed` helper, which renders an iframe with the rendered preview in it at any point in your document. | ||
|
||
An embedded component preview looks like this: | ||
|
||
<%= embed Feedback::BlankSlateComponentPreview, :default, params: { icon: true } %> | ||
|
||
To specify which preview example to render, the helper accepts a preview class and a method name (as a symbol), like this: | ||
|
||
```erb | ||
>%= embed Feedback:BlankSlateComponentPreview, :default %< | ||
``` | ||
|
||
## Preview params | ||
|
||
If you have configured your examples to accept preview params then you can supply values for those params when rendering the embedded preview: | ||
|
||
```erb | ||
>%= embed Feedback:BlankSlateComponentPreview, :default, params: { | ||
icon: true, | ||
title: "No content yet" | ||
} %< | ||
``` |
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,7 @@ | ||
--- | ||
label: Further info | ||
--- | ||
|
||
These pages are only intended to give an example of what documentation pages in Lookbook look like. | ||
|
||
For more info and full documentation, check out the [Lookbook repository →](https://github.com/allmarkedup/lookbook) |
3 changes: 2 additions & 1 deletion
3
test/components/previews/feedback/blank_slate_component_preview.rb
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