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 4 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)
- ## [Buttons](/teamshares/recipes/buttons.md)
<!-- - ## [Cypress tests](/teamshares/recipes/cypress.md) -->
216 changes: 216 additions & 0 deletions docs/teamshares/recipes/buttons.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
# Button Playbook
kdonovan marked this conversation as resolved.
Show resolved Hide resolved

# Types of buttons

## 1. Link buttons

<aside>
💡 Hint: these are buttons marked with external: true or marked with render_as_link: true

</aside>
kdonovan marked this conversation as resolved.
Show resolved Hide resolved

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

<aside>
💡 Hint: use target="_blank" to open the link in a new tab

</aside>

## 2. Submit button

<aside>
💡 Hint: these are commonly used with simpleform and have submit: true

</aside>

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

<aside>
💡 Hint: to render in a content_tag, this is how you would do so:

</aside>

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

<aside>
💡 For more information check out [our Rails UJS recipe page](https://design.teamshares.com/#/teamshares/recipes/rails-ujs)

</aside>

```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")
```

<aside>
💡 Hint: you may need to run the following commands for modal buttons to work locally:

</aside>

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

<aside>
💡 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)

</aside>

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

<aside>
💡 Hint: move the icon before or after the text with “prefix” or “suffix”

</aside>

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