Skip to content

Commit

Permalink
feat(@lapidist/button): init
Browse files Browse the repository at this point in the history
  • Loading branch information
brettdorrans committed Dec 3, 2019
1 parent 055db65 commit 44ada6a
Show file tree
Hide file tree
Showing 8 changed files with 283 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/button/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.ts
!*.d.ts
*.spec.js
*.spec.d.ts
*.tsx
*.mdx
tsconfig.json
__snapshots__
jest.config.js
65 changes: 65 additions & 0 deletions packages/button/Button.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
name: Button
route: /components/Button
menu: Components
---

import { Playground, Props } from 'docz';
import Button from './src';

# Button

## When to use

- **Buttons are used to initialise an action.** They have labels that express what action happens when the user interacts with it.
- **Buttons are used primarily for actions.** Examples include Add, Save, Delete, or Create.
- **Do not use buttons as navigation elements.** Instead, use [links](#) for navigation.
- **Primary buttons always appear to the right.** Secondary buttons appear to the left of the primary button.

## Props

<Props of={Button} />

## Examples

### Default Button

<Playground>
<Button
text="Click me"
block
/>
<Button
text="Click me"
block
loading
/>
<Button
text="Click me"
block
outline
/>
<Button
text="Click me"
/>
<Button
text="Click me"
disabled
/>
<Button
text="Click me"
outline
small
/>
<Button
text="Click me"
small
loading
/>
<Button
text="Click me"
outline
disabled
small
/>
</Playground>
1 change: 1 addition & 0 deletions packages/button/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../../jest.config');
23 changes: 23 additions & 0 deletions packages/button/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "@lapidist/button",
"version": "0.0.0",
"description": "Button component",
"author": "Brett Dorrans <[email protected]>",
"license": "MIT",
"main": "src/index.js",
"scripts": {
"build": "tsc -p tsconfig.json",
"test": "jest"
},
"publishConfig": {
"access": "public"
},
"release": {
"analyzeCommits": {
"preset": "angular",
"releaseRules": [
{"type": "build", "release": "minor"}
]
}
}
}
55 changes: 55 additions & 0 deletions packages/button/src/Button.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React from 'react';
import renderer from 'react-test-renderer';
import 'jest-styled-components';

import Button from './index';

test('it works', () => {
const tree = renderer.create(<Button text="Click me" />).toJSON();
expect(tree).toMatchSnapshot();
});

test('it works as block', () => {
const tree = renderer.create(<Button text="Click me" block />).toJSON();
expect(tree).toMatchSnapshot();
});

test('it works as block loading', () => {
const tree = renderer
.create(<Button text="Click me" block loading />)
.toJSON();
expect(tree).toMatchSnapshot();
});

test('it works as block outline', () => {
const tree = renderer
.create(<Button text="Click me" block outline />)
.toJSON();
expect(tree).toMatchSnapshot();
});

test('it works as disabled', () => {
const tree = renderer.create(<Button text="Click me" disabled />).toJSON();
expect(tree).toMatchSnapshot();
});

test('it works as outline small', () => {
const tree = renderer
.create(<Button text="Click me" outline small />)
.toJSON();
expect(tree).toMatchSnapshot();
});

test('it works as small loading', () => {
const tree = renderer
.create(<Button text="Click me" small loading />)
.toJSON();
expect(tree).toMatchSnapshot();
});

test('it works as outline small disabled', () => {
const tree = renderer
.create(<Button text="Click me" outline disabled small />)
.toJSON();
expect(tree).toMatchSnapshot();
});
81 changes: 81 additions & 0 deletions packages/button/src/__snapshots__/Button.spec.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`it works 1`] = `
<button
className=""
disabled={false}
type="button"
>
Click me
</button>
`;

exports[`it works as block 1`] = `
<button
className=""
disabled={false}
type="button"
>
Click me
</button>
`;

exports[`it works as block loading 1`] = `
<button
className=""
disabled={true}
type="button"
>
Click me
</button>
`;

exports[`it works as block outline 1`] = `
<button
className=""
disabled={false}
type="button"
>
Click me
</button>
`;

exports[`it works as disabled 1`] = `
<button
className=""
disabled={true}
type="button"
>
Click me
</button>
`;

exports[`it works as outline small 1`] = `
<button
className=""
disabled={false}
type="button"
>
Click me
</button>
`;

exports[`it works as outline small disabled 1`] = `
<button
className=""
disabled={true}
type="button"
>
Click me
</button>
`;

exports[`it works as small loading 1`] = `
<button
className=""
disabled={true}
type="button"
>
Click me
</button>
`;
44 changes: 44 additions & 0 deletions packages/button/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from 'react';
import styled from 'styled-components';

export interface ButtonProps {
/** The Button's id. */
readonly id?: string;
/** The Button's classname. */
readonly className?: string;
/** The Button's onClick callback function. */
readonly handleClick?: (event: React.MouseEvent) => void;
/** The Button's text. */
readonly text: string;
/** The Button's disabled state. Fades the Button out. */
readonly disabled?: boolean;
/** The Button's block state. Makes the Button full width. */
readonly block?: boolean;
/** The Button's outline state. Makes the Button have a border with no background. */
readonly outline?: boolean;
/** The Button's small state. Makes the button small. */
readonly small?: boolean;
/** The Button's loading state. Makes the button disabled and display loading icon. */
readonly loading?: boolean;
}

export const Button: React.FC<ButtonProps> = ({
id,
className,
text,
handleClick = undefined,
disabled = false,
loading = false
}) => (
<button
id={id}
className={className}
type="button"
onClick={handleClick}
disabled={disabled || loading}
>
{text}
</button>
);

export default styled(Button)``;
5 changes: 5 additions & 0 deletions packages/button/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "http://json.schemastore.org/tsconfig",
"extends": "../../tsconfig.base.json",
"include": ["src/**/*.ts", "src/**/*.tsx"]
}

0 comments on commit 44ada6a

Please sign in to comment.