1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 01:39:44 +01:00
metamask-extension/ui/components/component-library
Garrett Bear 66292330fe
Feat/18890/button ts update (#20492)
* button to TS migration

working demo

style props

broken mapping - need switch

working types file

working types

fix dependent imports of Button

variant mapping

working types

fix lint

fix test

fix ButtonSize issue on QuizContent

box fix

test if this works

fix button being used on QuizContent

fix button_variant import

readme fix

* fix button import

* fix primary button as anchor hover

* deprecated

* button to TS migration

fix lint

fix test

* fix rebase issue

* fix rebase issue

* lint fix
2023-08-28 14:42:00 -07:00
..
avatar-account Removing Box props description from TS component docs (#20451) 2023-08-16 10:34:08 -07:00
avatar-base Removing Box props description from TS component docs (#20451) 2023-08-16 10:34:08 -07:00
avatar-favicon fix/TagUrl to TS (#20519) 2023-08-18 17:59:02 -07:00
avatar-icon Removing Box props description from TS component docs (#20451) 2023-08-16 10:34:08 -07:00
avatar-network Removing Box props description from TS component docs (#20451) 2023-08-16 10:34:08 -07:00
avatar-token Removing Box props description from TS component docs (#20451) 2023-08-16 10:34:08 -07:00
badge-wrapper Removing Box props description from TS component docs (#20451) 2023-08-16 10:34:08 -07:00
banner-alert fix/BannerBase to TS (#20421) 2023-08-18 14:52:40 -07:00
banner-base fix/BannerBase to TS (#20421) 2023-08-18 14:52:40 -07:00
banner-tip fix/BannerBase to TS (#20421) 2023-08-18 14:52:40 -07:00
box fix/BannerBase to TS (#20421) 2023-08-18 14:52:40 -07:00
button Feat/18890/button ts update (#20492) 2023-08-28 14:42:00 -07:00
button-base Removing Box props description from TS component docs (#20451) 2023-08-16 10:34:08 -07:00
button-icon Removing Box props description from TS component docs (#20451) 2023-08-16 10:34:08 -07:00
button-link Updating props to optional and providing defaults (#20448) 2023-08-15 09:38:36 -07:00
button-primary Feat/18890/button ts update (#20492) 2023-08-28 14:42:00 -07:00
button-secondary Updating props to optional and providing defaults (#20448) 2023-08-15 09:38:36 -07:00
checkbox Removing Box props description from TS component docs (#20451) 2023-08-16 10:34:08 -07:00
form-text-field Fix/helptext to ts (#20108) 2023-07-21 10:11:35 -07:00
header-base Feat/18890/button ts update (#20492) 2023-08-28 14:42:00 -07:00
help-text Removing Box props description from TS component docs (#20451) 2023-08-16 10:34:08 -07:00
icon Removing Box props description from TS component docs (#20451) 2023-08-16 10:34:08 -07:00
input Feat/18890/button ts update (#20492) 2023-08-28 14:42:00 -07:00
label Removing Box props description from TS component docs (#20451) 2023-08-16 10:34:08 -07:00
modal Removing Box props description from TS component docs (#20451) 2023-08-16 10:34:08 -07:00
modal-content Feat/18890/button ts update (#20492) 2023-08-28 14:42:00 -07:00
modal-focus Adding ModalFocus component (#18979) 2023-05-09 14:33:29 -07:00
modal-header Feat/18890/button ts update (#20492) 2023-08-28 14:42:00 -07:00
modal-overlay Removing Box props description from TS component docs (#20451) 2023-08-16 10:34:08 -07:00
picker-network Fix-Migrate Picker-Network to TS (#20365) 2023-08-04 10:11:55 -07:00
popover migration of Popover to use TS Box version (#20279) 2023-08-04 11:11:32 -07:00
popover-header Feat/18890/button ts update (#20492) 2023-08-28 14:42:00 -07:00
tag Removing Box props description from TS component docs (#20451) 2023-08-16 10:34:08 -07:00
tag-url fix/TagUrl to TS (#20519) 2023-08-18 17:59:02 -07:00
text Removing Box props description from TS component docs (#20451) 2023-08-16 10:34:08 -07:00
text-field Update Text import paths: component library/ (#19987) 2023-07-17 14:00:16 -07:00
text-field-search Updating Icon types and component to use TS Box component (#19990) 2023-07-25 09:05:37 -07:00
component-library-components.scss Feat/15438/create ds checkbox component (#19808) 2023-07-14 11:50:47 -07:00
COMPONENT-LIBRARY.stories.mdx Updating component-library readme storybook render (#19359) 2023-06-05 21:23:25 +05:30
index.js Feat/18890/button ts update (#20492) 2023-08-28 14:42:00 -07:00
README.md Component library readme update (#20105) 2023-07-19 22:10:45 -07:00

Component Library

This folder contains design system components that are built 1:1 with the Figma DS Components UI kit and should be used where possible in all UI feature work.

Architecture

All components are built on top of the Box component and accept all Box component props.

Layout

component-library components accept all Box component style utility props for layout. They can be used in conjunction with the enums from ui/helpers/constants/design-system.ts

import { Display } from '../../../helpers/constants/design-system';
import { Text } from '../../component-library';

<Text marginBottom={4} display={Display.Flex} gap={4}>
  <span>This text has a margin-bottom of 16px</span>
  <span>It also has a display of flex and gap of 16px</span>
</Text>;

Polymorphic as prop and semantic HTML

component-library components accept a polymorphic as prop to change the root html element of a component

import { Text } from '../../component-library';

<ul>
  <Text as="li">This renders as list item html element</Text>
</ul>;

Style customization and access child components

We understand some customization to styles or access to children components is necessary when building UI. To ensure our components are flexible we intend to allow for customization and access though a pattern called inversion of control.

Styles

Note: If you are seeing a disparity between styles in Figma and code that's a red flag and could mean there is bug between design system Figma and code component. We recommend posting it on our slack channel #metamask-design-system so we can support you on it

We try to utilize the Box component style utility props as much as possible in our components. Style utility prop overrides should be your first option. This allows you to change styles right inside of the component and reduces the amount of CSS in the codebase. If there are no style utility props for the customization required you can attach a class name to the component using the className prop and add styling using CSS.

import { BackgroundColor } from '../../../helpers/constants/design-system';
import { Button } from '../../component-library';

// Overriding the browser default styling using style utility props
<Text
  as="button"
  backgroundColor={BackgroundColor.transparent}
  onClick={handleOnClick}
>
  Renders as a button but has a transparent background
</Text>;

<Text
  as="button"
  backgroundColor={BackgroundColor.transparent}
  onClick={handleOnClick}
  className="nft-feature__title"
>
  Adding a custom className to add additional styles using CSS
</Text>;

Access to child components

All of our components should allow access to children components through an object prop. The example below adds a data test id to the child Text component inside BannerAlert.

import { Severity } from '../../../helpers/constants/design-system';
import { BannerAlert } from '../../component-library';

<BannerAlert
  severity={Severity.Danger}
  title="This allows a third party to access and transfer all of your NFTs"
  titleProps={{ 'data-testid': 'approve-token-banner-title' }}
/>;

Accessibility

Allowing everyone to access web3 regardless of disability is an important part of what we do at MetaMask. Ensuring accessibility in our components is a priority. We strive to achieve this by maintaining proper color contrast in our components and implementing necessary aria label props. If you have any questions regarding accessibility reach out and we will support you as much as possible. Additionally, your suggestions for improvement are welcome, as we continue our journey towards greater accessibility. Together, let's create an inclusive web3 experience for all 🦾

TypeScript

We are currently in the process of migrating all component-library components to TypeScript. Feel free to contribute by creating a PR against one of these issues

Support

If internal folks have any questions please reach out the design system team via the internal slack channel #metamask-design-system 💁

DS components figma file