0.47.4 • Published 1 day ago

@justeattakeaway/pie-button v0.47.4

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
1 day ago

Table of Contents

  1. Introduction
  2. Installation
  3. Importing the component
  4. Peer Dependencies
  5. Props
  6. Events
  7. Forms usage
  8. Contributing

pie-button

pie-button is a Web Component built using the Lit library. It offers a simple and accessible button component for web applications.

This component can be easily integrated into various frontend frameworks and customized through a set of properties.

Installation

To install pie-button in your application, run the following on your command line:

# npm
$ npm i @justeattakeaway/pie-button

# yarn
$ yarn add @justeattakeaway/pie-button

For full information on using PIE components as part of an application, check out the Getting Started Guide.

Importing the component

JavaScript

// Default – for Native JS Applications, Vue, Angular, Svelte, etc.
import { PieButton } from '@justeattakeaway/pie-button';

// If you don't need to reference the imported object, you can simply
// import the module which registers the component as a custom element.
import '@justeattakeaway/pie-button';

React

// React
// For React, you will need to import our React-specific component build
// which wraps the web component using @lit-labs/react
import { PieButton } from '@justeattakeaway/pie-button/dist/react';

!NOTE When using the React version of the component, please make sure to also include React as a peer dependency in your project.

Peer Dependencies

!IMPORTANT When using pie-button, you will also need to include a couple of dependencies to ensure the component renders as expected. See the PIE Wiki for more information and how to include these in your application.

Props

PropertyTypeDefaultDescription
sizeStringmediumSize of the button, one of sizesxsmall, small-expressive, small-productive, medium, large
typeStringsubmitType of the button, one of typessubmit, button, reset. Read further on MDN
variantStringprimaryVariant of the button, one of variantsprimary, secondary, outline, ghost, destructive, destructive-ghost, inverse, ghost-inverse, outline-inverse
disabledBooleanfalseIf true, disables the button.
isFullWidthBooleanfalseIf true, sets the button width to 100% of its container.
isLoadingBooleanfalseIf true, displays a loading indicator inside the button.
isResponsiveBooleanfalseIf true, uses the next larger size on wide viewports.
iconPlacementStringleadingIcon placements of the icon slot, if provided, one of iconPlacements - leading, trailing
nameStringundefinedThe name of the button, to be submitted with form data. Read further on MDN
valueStringundefinedThe value of the button, to be submitted with form data. Read further on MDN
formactionStringundefinedDesignates an alternative URL for form data submission. Read further on MDN
formenctypeStringundefinedSpecifies the form data encoding type. Read further on MDN
formmethodStringundefinedSets the HTTP method for form data. Read further on MDN
formnovalidateBooleanundefinedEnsures the form is submitted without native HTML validation. Read further on MDN
formtargetStringundefinedDictates where to display the response after form submission. Read further on MDN
responsiveSizeStringproductiveSets a specific size for xsmall button when rendered as responsive. It can be productive or expressive.

In your markup or JSX, you can then use these to set the properties for the pie-button component:

<!-- Native HTML -->
<pie-button size='medium' type='button' variant='primary'>Click me!</pie-button>

<!-- JSX -->
<PieButton size='medium' type='button' variant='primary'>Click me!</PieButton>

Slots

SlotDescription
Default slotThe default slot is used to pass text into the button component.
iconUsed to pass in an icon to the button component. The icon placement can be controlled via the iconPlacement prop and we recommend using pie-icons-webc for defining this icon, but this can also accept an SVG icon.

Using pie-icons-webc with pie-button icon slot

We recommend using pie-icons-webc when using the icon slot. Here is an example of how you would do this:

<!--
  Note that pie-button and the icon that you want to use will need to be imported as components into your application.
  See the `pie-icons-webc` README for more info on importing these icons.
-->
<pie-button>
    <icon-plus-circle slot="icon"></icon-plus-circle>
    Search
</pie-button>

Events

This component does not use any custom event handlers. In order to add event listening to this component, you can treat it like a native HTML element in your application.

For example, to add a click handler in various templates:

HTML

<!-- Other attributes omitted for clarity -->
<pie-button onclick="e => console.log(e)">Click me!</pie-button>

Vue templates (using Nuxt 3)

<!-- Other attributes omitted for clarity -->
<pie-button @click="handleClick">Click me!</pie-button>

React templates (using Next 13)

<!-- Other attributes omitted for clarity -->
<PieButton onClick={handleClick}>increment</PieButton>

Forms usage

The pie-button web component is designed to integrate with standard HTML forms just like a native HTML button. When positioned inside a form, the component will automatically associate itself, enabling it to directly interact with the form context.

Button Attributes

The pie-button provides a set of attributes to customize its behavior within forms:

  • type: Determines the button's function. Set to submit for form submissions or reset to clear form fields.
  • formaction: Designates an alternative URL for form data submission when this specific button is clicked.
  • formenctype: Specifies the form data encoding type during submission via this button.
  • formmethod: Sets the HTTP method (e.g., GET or POST) for form data when initiated by this button.
  • formnovalidate: If present, ensures the form is submitted without validation checks.
  • formtarget: Dictates where to display the response after form submission.

Please see the MDN docs for more information on these attributes.

Integration Example

<form action="/default-endpoint" method="post">
    <input type="text" name="username" required>
    <pie-button
        type="submit"
        formaction="/alternate-endpoint"
        formenctype="multipart/form-data"
        formmethod="post"
        formnovalidate
        formtarget="_blank">
        Submit
    </pie-button>
</form>

In this example:

  • The pie-button, when clicked, will send the form data to /alternate-endpoint instead of the form's default /default-endpoint.
  • It uses the multipart/form-data encoding type for form submission.
  • The form will submit using the POST method.
  • No validation will be performed during submission, thanks to formnovalidate.
  • The form's submission response will be opened in a new browser tab/window because of the formtarget="_blank" attribute.

Contributing

Check out our contributing guide for more information on local development and how to run specific component tests.

0.47.4

16 days ago

0.47.3

1 month ago

0.47.2

1 month ago

0.47.1

1 month ago

0.47.0

2 months ago

0.46.0

2 months ago

0.45.6

2 months ago

0.45.5

3 months ago

0.45.4

3 months ago

0.45.3

3 months ago

0.45.2

4 months ago

0.45.1

4 months ago

0.45.0

4 months ago

0.44.0

4 months ago

0.43.0

4 months ago

0.42.1

4 months ago

0.42.0

5 months ago

0.41.1

5 months ago

0.20.0

10 months ago

0.41.0

6 months ago

0.19.0

10 months ago

0.38.0

6 months ago

0.36.1

6 months ago

0.36.0

7 months ago

0.34.0

7 months ago

0.17.0

11 months ago

0.32.0

7 months ago

0.30.0

8 months ago

0.29.0

8 months ago

0.27.0

9 months ago

0.38.1-next.0

6 months ago

0.25.0

9 months ago

0.23.0

10 months ago

0.40.2

6 months ago

0.40.0

6 months ago

0.40.1

6 months ago

0.39.1

6 months ago

0.39.0

6 months ago

0.37.1

6 months ago

0.37.0

6 months ago

0.35.0

7 months ago

0.33.0

7 months ago

0.18.0

11 months ago

0.39.1-next.0

6 months ago

0.31.0

7 months ago

0.28.1

8 months ago

0.28.0

9 months ago

0.26.0

9 months ago

0.24.1

9 months ago

0.24.0

9 months ago

0.22.0

10 months ago

0.16.1

11 months ago

0.11.0

1 year ago

0.12.0

1 year ago

0.13.0

12 months ago

0.12.1

1 year ago

0.14.0

12 months ago

0.12.2

12 months ago

0.15.0

11 months ago

0.16.0

11 months ago

0.10.2

1 year ago

0.10.1

1 year ago

0.10.0

1 year ago

0.9.0

1 year ago

0.8.0

1 year ago

0.7.0

1 year ago

0.6.1

1 year ago

0.6.0

1 year ago

0.5.1

1 year ago

0.5.0

1 year ago

0.4.0

1 year ago

0.3.0

1 year ago