Skip to content
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

Open
wants to merge 5 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/teamshares/recipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

- ## [Protips](/teamshares/recipes/protips.md)
- ## [Rails UJS](/teamshares/recipes/rails-ujs.md)
- ## [Converting Button View Component To Shoelace](/teamshares/recipes/buttons.md)
Copy link
Author

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

Copy link
Collaborator

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 👍

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 page
In this case, I'd make the title just Converting SharedUI Buttons, and then under that a line that says Recipes for replacing various SharedUI::ButtonComponent usages with sl-button, to make it super explicit.

<!-- - ## [Cypress tests](/teamshares/recipes/cypress.md) -->
190 changes: 190 additions & 0 deletions docs/teamshares/recipes/buttons.md
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`

Choose a reason for hiding this comment

The 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 "SharedUI::ButtonComponents with external: true or render_as_link: true are rendered as HTML <a> tags. To get a similar effect in Shoelace, use sl-button with an href attribute."


### Before

```

Choose a reason for hiding this comment

The 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"]

Choose a reason for hiding this comment

The 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-button[
  size="large" 
  pill href="https://www.calendly.com/mickmoylan" 
  target="_blank"
]

sl-icon[slot="prefix" name="calendar"]

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The 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`

Choose a reason for hiding this comment

The 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}"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set the block format to pug instead of jsx and break the attributes to multiple lines

| 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:

Choose a reason for hiding this comment

The 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 sl-button in a Rails content_tag..."


```jsx

content_tag("sl-button", "Previous", pill: true, disabled: true, size: "small")
```

## 4. Stimulus Button

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pug and multiple-lines here as well

content_tag("sl-button", "Complete", variant: "primary", href: complete_path, pill: true, size: "small", type: "submit", "data-education--presentation-target": "nextLink")
```

## 5. Modal button

Choose a reason for hiding this comment

The 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.

Choose a reason for hiding this comment

The 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 SharedUI::ButtonComponents that are used to launch modals..."

### 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pug

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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to put the :get, :post, ButtonTo etc in code format for readability


### Before

```
= render SharedUI::ButtonComponent.new(
text: "Complete",
link: complete_path,
data: {
"education--presentation-target" => "nextLink",
},
submit: true,
size: "small",
type: "primary",
)
```

### After

```jsx

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pug

# 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
```