-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Button Playbook #5
base: next
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
# How to convert SharedUI::Button usages to Shoelace | ||
|
||
## 1. Link button | ||
|
||
> 💡 Hint: these are buttons marked with `external: true` or marked with `render_as_link: true` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like these little blockquote hints. The italicized emoji looks a bit weird, but we can figure out formatting for that later. I think some of the hints here should just be paragraphs of explanation, in which I'd err on the side of over-explaining. Here, I would just make this a paragraph that says " |
||
|
||
### Before | ||
|
||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For all of these code blocks, you can get the right formatting via ```pug |
||
= render SharedUI::ButtonComponent.new(\ | ||
text: "Schedule prep session", | ||
link: "https://www.calendly.com/mickmoylan", | ||
icon: "calendar_icon", | ||
external: true, | ||
method: "get", | ||
size: "medium", | ||
type: "outlined") | ||
``` | ||
|
||
### After | ||
|
||
``` | ||
sl-button[size="large" pill href="https://www.calendly.com/mickmoylan" target="_blank"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the shoelace examples, I'd prefer to put the individual attributes on their own lines to encourage readability:
|
||
sl-icon[slot="prefix" name="calendar"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the examples that only have one or two attributes, we don't need the [] at all |
||
| Schedule prep session | ||
``` | ||
|
||
> 💡 Hint: use `target="_blank"` to open the link in a new tab | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And then short little tips like this can remain as "hints". |
||
|
||
## 2. Submit button | ||
|
||
> 💡 Hint: these are commonly used with simpleform and have `submit: true` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here again I would lengthen this explanation a bit and make it just a regular paragraph |
||
|
||
### Before | ||
|
||
``` | ||
= render SharedUI::ButtonComponent.new(\ | ||
text: "Accept", | ||
type: "primary", | ||
data: { test_id: "accept-event-button" }, | ||
submit: true, | ||
disabled: preview ? true : false, | ||
options: { classes: "ml-2", name: "accept", value: "Accept" }) | ||
``` | ||
|
||
### After | ||
|
||
```jsx | ||
sl-button[size="large" pill type="submit" data-test_id="accept-event-button" variant="primary" disabled="#{preview ? true : false}"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Set the block format to |
||
| Accept | ||
``` | ||
|
||
## 3. Disabled button | ||
|
||
### Before | ||
|
||
``` | ||
render SharedUI::ButtonComponent.new( | ||
text: "Previous", | ||
link: nil, | ||
disabled: true, | ||
size: "small", | ||
type: "outlined", | ||
) | ||
``` | ||
|
||
### After | ||
|
||
```jsx | ||
sl-button[size="small" pill disabled="true"] | ||
| Previous | ||
``` | ||
|
||
> 💡 Hint: to render in a content_tag, this is how you would do so: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we're talking about two subjects that are both being rendered, it will be clearer to make the subject explicit, i.e., "To render an |
||
|
||
```jsx | ||
|
||
content_tag("sl-button", "Previous", pill: true, disabled: true, size: "small") | ||
``` | ||
|
||
## 4. Stimulus Button | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a brief paragraph here about what this means (a button that is hooked up to actions in a Stimulus controller) |
||
|
||
### Before | ||
|
||
``` | ||
render SharedUI::ButtonComponent.new( | ||
text: "Complete", | ||
link:complete_path, | ||
data: { | ||
"education--presentation-target" => "nextLink", | ||
}, | ||
submit: true, | ||
size: "small", | ||
type: "primary", | ||
) | ||
``` | ||
|
||
### After (this example uses a content tag) | ||
|
||
```jsx | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
content_tag("sl-button", "Complete", variant: "primary", href: complete_path, pill: true, size: "small", type: "submit", "data-education--presentation-target": "nextLink") | ||
``` | ||
|
||
## 5. Modal button | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the modals in Buyout are a bit different from the ones in OS, so we may need to update this to make that clear. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would also add a little context about what we're talking about here, i.e., "To replace |
||
### Before | ||
|
||
``` | ||
render SharedUI::ButtonComponent.new( | ||
text: "Presentations", | ||
link:path, | ||
modal: true, | ||
method: "get", | ||
size: "medium", | ||
type: "outlined", | ||
) | ||
``` | ||
|
||
### After (this example uses a content tag) | ||
|
||
> 💡 For more information check out [our Rails UJS recipe page](https://design.teamshares.com/#/teamshares/recipes/rails-ujs) | ||
|
||
```jsx | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
content_tag("sl-button", "Presentations", size: "large", pill: true, href: *path*, "data-toggle": "modal", "data-remote": true, "data-dismissible": true, "data-close-others": true, "data-method": "get") | ||
``` | ||
|
||
> 💡 Hint: you may need to run the following commands for modal buttons to work locally: | ||
|
||
``` | ||
yarn cache clean && rm -rf node_modules | ||
``` | ||
|
||
``` | ||
yarn add https://github.com/teamshares/shared-ui.git#main | ||
``` | ||
|
||
``` | ||
yarn build --watch | ||
``` | ||
|
||
## 6. Internal link/path with no explicit associated form | ||
|
||
> 💡 Hint: for :get requests you can just use a link button above, for :delete, :post, :patch, etc. we now have a ButtonTo view component that behaves as rails’ [button_to](https://apidock.com/rails/ActionView/Helpers/UrlHelper/button_to) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sure to put the |
||
|
||
### Before | ||
|
||
``` | ||
= render SharedUI::ButtonComponent.new( | ||
text: "Complete", | ||
link: complete_path, | ||
data: { | ||
"education--presentation-target" => "nextLink", | ||
}, | ||
submit: true, | ||
size: "small", | ||
type: "primary", | ||
) | ||
``` | ||
|
||
### After | ||
|
||
```jsx | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
# the default method here is "post", can pass in a method field to change | ||
= render SharedUI::ButtonToComponent.new(text: "Complete", path: complete_path, options: {"data-education--presentation-target": "nextLink"}) | ||
``` | ||
|
||
## 7. Icon button | ||
|
||
> 💡 Hint: move the icon before or after the text with “prefix” or “suffix” | ||
|
||
### Before | ||
|
||
```jsx | ||
= render SharedUI::ButtonComponent.new(\ | ||
text: "Schedule prep session", | ||
link: "https://www.calendly.com/mickmoylan", | ||
icon: "calendar_icon", | ||
external: true, | ||
method: "get", | ||
size: "medium", | ||
type: "outlined") | ||
``` | ||
|
||
### After | ||
|
||
```jsx | ||
sl-button[size="large" pill href="[https://www.calendly.com/mickmoylan](https://www.calendly.com/mickmoylan)" target="_blank"] | ||
sl-icon[slot="prefix" name="calendar"] | ||
| Schedule prep session | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kdonovan updated naming here as well, do you think it's worth to change the file name? Or keep since this is the only recipe book for buttons
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, let's just tweak it to e.g.
shared-ui-buttons.md
👍There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this, I'm realizing that we should probably:
a. Make the link titles short and pithy so they fit easily in the sidebar, and
b. Add a little description line under each of them on this
recipes.md
pageIn this case, I'd make the title just
Converting SharedUI Buttons
, and then under that a line that saysRecipes for replacing various SharedUI::ButtonComponent usages with sl-button
, to make it super explicit.