Skip to content

Commit

Permalink
Merge pull request #34 from josemarluedke/feat/renderless-button
Browse files Browse the repository at this point in the history
Add renderless Button
  • Loading branch information
josemarluedke authored Feb 23, 2020
2 parents 416181e + 8146d02 commit 97c9490
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 7 deletions.
18 changes: 11 additions & 7 deletions packages/buttons/addon/components/button.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ Intents:
--}}

{{!-- template-lint-disable require-button-type --}}
<button
type={{this.type}}
class={{this.classNames}}
...attributes
>
{{yield}}
</button>
{{#if @isRenderless}}
{{yield (hash classNames=this.classNames)}}
{{else}}
<button
type={{this.type}}
class={{this.classNames}}
...attributes
>
{{yield}}
</button>
{{/if}}
1 change: 1 addition & 0 deletions packages/buttons/addon/components/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface ButtonArgs {
isSmall?: boolean;
isLarge?: boolean;
isXLarge?: boolean;
isRenderless?: boolean;
}

export default class Button extends Component<ButtonArgs> {
Expand Down
9 changes: 9 additions & 0 deletions packages/buttons/tests/integration/components/button-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,13 @@ module('Integration | Component | Button', function(hooks) {
});
});
});

test('it yields classNames when renderless', async function(assert) {
await render(
hbs`<Button @isRenderless={{true}} as |btn|>
<div data-test-id="my-div">{{btn.classNames}}</div>
</Button>`
);
assert.dom('[data-test-id="my-div"]').hasText('btn');
});
});
12 changes: 12 additions & 0 deletions packages/docs/app/components/demo/buttons/button-renderless.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<DocsDemo as |demo|>
{{#demo.example name="demo-buttons-button-renderless.hbs"}}
<Button @isRenderless={{true}} as |btn|>
<a href="javascript:void(0)" class={{btn.classNames}}>My Llink</a>
</Button>
{{/demo.example}}

<demo.snippet
@name="demo-buttons-button-renderless.hbs"
@label="components/demo.hbs"
/>
</DocsDemo>
10 changes: 10 additions & 0 deletions packages/docs/app/templates/docs/buttons/button.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ Here are the possible sizes and its argument name.

<Demo::Buttons::ButtonSizes />

## Renderless

Sometimes a button element is not ideal for a given case, but the same styles are still desired.
Frontile provides the option to disable rendering the element, but instead yield back an object with
the class names it would use.

To enable this behavior, pass `@isRenderless` as true to the `Button` component.

<Demo::Buttons::ButtonRenderless />

## `@type` Argument

Use the `@type` argument to modify the `type` attribute of the button. By default, `button` will be used.
Expand Down
2 changes: 2 additions & 0 deletions packages/docs/app/templates/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ Packages:

- `@frontile/core`
- `@frontile/forms`
- `@frontile/changeset-form`
- `@frontile/buttons`

0 comments on commit 97c9490

Please sign in to comment.