diff --git a/src/components/button/styles.ts b/src/components/button/styles.ts index 95193049..ad560894 100644 --- a/src/components/button/styles.ts +++ b/src/components/button/styles.ts @@ -57,6 +57,13 @@ const buttonColors = (dark: string, base: string, kind: string) => { return base; }; + const borderColor = (): ColorGroup | string => { + if (isPrimary) return base; + if (isSecondary) return lightGrey; + if (isTertiary) return lightestGrey; + return dark; + }; + const hoverTextColor = (): ColorGroup | string => { if (isPrimary) return lightBase; if (isSecondary) return darkBase; @@ -65,7 +72,7 @@ const buttonColors = (dark: string, base: string, kind: string) => { }; return { - borderColor: isPrimary ? base : lightGrey, + borderColor: borderColor(), backgroundColor: isPrimary ? base : 'transparent', textColor: textColor(), hoverBackgroundColor: isPrimary ? dark : lightestGrey, diff --git a/src/components/elevated/Elevated.spec.tsx b/src/components/elevated/Elevated.spec.tsx index 0fc9c24c..227d3c19 100644 --- a/src/components/elevated/Elevated.spec.tsx +++ b/src/components/elevated/Elevated.spec.tsx @@ -6,8 +6,8 @@ import 'jest-styled-components'; import { ThemeProvider } from '../theme-provider'; import { Elevated, ElevationHeight } from './index'; -const setup = (Tag: React.ReactElement) => - render({Tag}); +const setup = (Elevated: React.ReactElement) => + render({Elevated}); test('it works', () => { const { container } = setup(Hello world); diff --git a/src/components/text/README.md b/src/components/text/README.md deleted file mode 100644 index 5c5c6a73..00000000 --- a/src/components/text/README.md +++ /dev/null @@ -1,9 +0,0 @@ -The Text component is a layout primitive for typography. - -```jsx harmony -import { ThemeProvider, Text } from '@lapidist/components'; - - - Nunc porttitor lectus ex, eu pharetra elit placerat non. Suspendisse nec ultrices augue, et varius velit. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Morbi sollicitudin sed turpis et vulputate. Nam consequat porttitor scelerisque. Nulla ultricies enim at eros accumsan interdum. Aenean egestas enim mi, nec tincidunt libero gravida et. - -``` diff --git a/src/components/toggle/Toggle.spec.tsx b/src/components/toggle/Toggle.spec.tsx new file mode 100644 index 00000000..0a491c20 --- /dev/null +++ b/src/components/toggle/Toggle.spec.tsx @@ -0,0 +1,31 @@ +import * as React from 'react'; +import { render } from '@testing-library/react'; +import '@testing-library/jest-dom'; +import 'jest-styled-components'; + +import { ThemeProvider } from '../theme-provider'; +import { ButtonKind } from '../button'; +import { Toggle } from './index'; + +const setup = (Toggle: React.ReactElement) => + render({Toggle}); + +const kinds: ButtonKind[] = ['primary', 'secondary', 'tertiary', 'danger']; + +test('it works', () => { + kinds.forEach((kind) => { + const { container } = setup(Hello world); + expect(container.firstChild).toMatchSnapshot(); + }); +}); + +test('it works with checked', () => { + kinds.forEach((kind) => { + const { container } = setup( + + Hello world + + ); + expect(container.firstChild).toMatchSnapshot(); + }); +}); diff --git a/src/components/toggle/Toggle.stories.tsx b/src/components/toggle/Toggle.stories.tsx new file mode 100644 index 00000000..19c1e126 --- /dev/null +++ b/src/components/toggle/Toggle.stories.tsx @@ -0,0 +1,54 @@ +import * as React from 'react'; +import { ThemeProvider } from '../theme-provider'; +import { Toggle } from './index'; +import { Box } from '../box'; + +export default { + title: 'Components/Toggle', + component: Toggle, + decorators: [(getStory) => {getStory()}] +}; + +const DefaultTemplate = (args) => { + const [checked, setChecked] = React.useState(false); + return ( + setChecked(!checked)} + {...args} + /> + ); +}; + +export const SingleToggle = (args) => ( + Toggle +); + +export const MultiToggle = (args) => { + const [option1Checked, setOption1Checked] = React.useState(false); + const [option2Checked, setOption2Checked] = React.useState(false); + + return ( + + setOption1Checked(!option1Checked)} + {...args} + > + Option 1 + + setOption2Checked(!option2Checked)} + {...args} + > + Option 2 + + + ); +}; diff --git a/src/components/toggle/__snapshots__/Toggle.spec.tsx.snap b/src/components/toggle/__snapshots__/Toggle.spec.tsx.snap new file mode 100644 index 00000000..7418fc63 --- /dev/null +++ b/src/components/toggle/__snapshots__/Toggle.spec.tsx.snap @@ -0,0 +1,977 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`it works 1`] = ` +.c1 { + border-style: solid; + text-align: center; + display: inline-block; + position: relative; + font-size: 1rem; + font-weight: 500; + border-radius: 9999px; + border-width: 2px; + box-shadow: 0 2px 3px rgba(0,0,0,0.1); + padding-left: 1rem; + padding-right: 1rem; + padding-top: 0.5rem; + padding-bottom: 0.5rem; + background-color: #17a3a5; + color: white; + border-color: #17a3a5; + border-top-color: transparent; + border-right-color: transparent; + border-bottom-color: transparent; + border-left-color: transparent; +} + +.c1:hover { + cursor: pointer; + background-color: #135f61; + color: white; +} + +.c1:hover:disabled { + cursor: not-allowed; + background-color: #135f61; +} + +.c1:disabled { + opacity: 0.7; + background-color: #135f61; + color: white; +} + +.c0 { + border-style: solid; + text-align: center; + display: inline-block; + position: relative; + font-size: 1rem; + font-weight: 500; + font-family: Montserrat,sans-serif; + line-height: 2; + border-radius: 9999px; + border-width: 2px; + box-shadow: 0 2px 3px rgba(0,0,0,0.1); + padding-left: 1rem; + padding-right: 1rem; + padding-top: 0.5rem; + padding-bottom: 0.5rem; + background-color: #17a3a5; + color: white; + border-color: #17a3a5; + border-top-color: transparent; + border-right-color: transparent; + border-bottom-color: transparent; + border-left-color: transparent; +} + +.c0:hover { + cursor: pointer; + background-color: #135f61; + color: white; +} + +.c0:hover:disabled { + cursor: not-allowed; + background-color: #135f61; +} + +.c0:disabled { + opacity: 0.7; + background-color: #135f61; + color: white; +} + +.c2 { + opacity: 1; + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; +} + + +`; + +exports[`it works 2`] = ` +.c2 { + opacity: 1; + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; +} + +.c1 { + border-style: solid; + text-align: center; + display: inline-block; + position: relative; + font-size: 1rem; + font-weight: 500; + border-radius: 9999px; + border-width: 2px; + box-shadow: 0 2px 3px rgba(0,0,0,0.1); + padding-left: 1rem; + padding-right: 1rem; + padding-top: 0.5rem; + padding-bottom: 0.5rem; + background-color: transparent; + color: #17a3a5; + border-color: #d4d4d4; + border-top-color: transparent; + border-right-color: transparent; + border-bottom-color: transparent; + border-left-color: transparent; +} + +.c1:hover { + cursor: pointer; + background-color: #fafafa; + color: #135f61; +} + +.c1:hover:disabled { + cursor: not-allowed; + background-color: #fafafa; +} + +.c1:disabled { + opacity: 0.7; + background-color: #fafafa; + color: #292B3E; +} + +.c0 { + border-style: solid; + text-align: center; + display: inline-block; + position: relative; + font-size: 1rem; + font-weight: 500; + font-family: Montserrat,sans-serif; + line-height: 2; + border-radius: 9999px; + border-width: 2px; + box-shadow: 0 2px 3px rgba(0,0,0,0.1); + padding-left: 1rem; + padding-right: 1rem; + padding-top: 0.5rem; + padding-bottom: 0.5rem; + background-color: transparent; + color: #17a3a5; + border-color: #d4d4d4; + border-top-color: transparent; + border-right-color: transparent; + border-bottom-color: transparent; + border-left-color: transparent; +} + +.c0:hover { + cursor: pointer; + background-color: #fafafa; + color: #135f61; +} + +.c0:hover:disabled { + cursor: not-allowed; + background-color: #fafafa; +} + +.c0:disabled { + opacity: 0.7; + background-color: #fafafa; + color: #292B3E; +} + + +`; + +exports[`it works 3`] = ` +.c2 { + opacity: 1; + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; +} + +.c1 { + border-style: solid; + text-align: center; + display: inline-block; + position: relative; + font-size: 1rem; + font-weight: 500; + border-radius: 9999px; + border-width: 2px; + box-shadow: 0 2px 3px rgba(0,0,0,0.1); + padding-left: 1rem; + padding-right: 1rem; + padding-top: 0.5rem; + padding-bottom: 0.5rem; + background-color: transparent; + color: #73748b; + border-color: #fafafa; + border-top-color: transparent; + border-right-color: transparent; + border-bottom-color: transparent; + border-left-color: transparent; +} + +.c1:hover { + cursor: pointer; + background-color: #fafafa; + color: #292B3E; +} + +.c1:hover:disabled { + cursor: not-allowed; + background-color: #fafafa; +} + +.c1:disabled { + opacity: 0.7; + background-color: #fafafa; + color: #292B3E; +} + +.c0 { + border-style: solid; + text-align: center; + display: inline-block; + position: relative; + font-size: 1rem; + font-weight: 500; + font-family: Montserrat,sans-serif; + line-height: 2; + border-radius: 9999px; + border-width: 2px; + box-shadow: 0 2px 3px rgba(0,0,0,0.1); + padding-left: 1rem; + padding-right: 1rem; + padding-top: 0.5rem; + padding-bottom: 0.5rem; + background-color: transparent; + color: #73748b; + border-color: #fafafa; + border-top-color: transparent; + border-right-color: transparent; + border-bottom-color: transparent; + border-left-color: transparent; +} + +.c0:hover { + cursor: pointer; + background-color: #fafafa; + color: #292B3E; +} + +.c0:hover:disabled { + cursor: not-allowed; + background-color: #fafafa; +} + +.c0:disabled { + opacity: 0.7; + background-color: #fafafa; + color: #292B3E; +} + + +`; + +exports[`it works 4`] = ` +.c2 { + opacity: 1; + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; +} + +.c1 { + border-style: solid; + text-align: center; + display: inline-block; + position: relative; + font-size: 1rem; + font-weight: 500; + border-radius: 9999px; + border-width: 2px; + box-shadow: 0 2px 3px rgba(0,0,0,0.1); + padding-left: 1rem; + padding-right: 1rem; + padding-top: 0.5rem; + padding-bottom: 0.5rem; + background-color: transparent; + color: #b41e25; + border-color: #810000; + border-top-color: transparent; + border-right-color: transparent; + border-bottom-color: transparent; + border-left-color: transparent; +} + +.c1:hover { + cursor: pointer; + background-color: #fafafa; + color: #810000; +} + +.c1:hover:disabled { + cursor: not-allowed; + background-color: #fafafa; +} + +.c1:disabled { + opacity: 0.7; + background-color: #fafafa; + color: #292B3E; +} + +.c0 { + border-style: solid; + text-align: center; + display: inline-block; + position: relative; + font-size: 1rem; + font-weight: 500; + font-family: Montserrat,sans-serif; + line-height: 2; + border-radius: 9999px; + border-width: 2px; + box-shadow: 0 2px 3px rgba(0,0,0,0.1); + padding-left: 1rem; + padding-right: 1rem; + padding-top: 0.5rem; + padding-bottom: 0.5rem; + background-color: transparent; + color: #b41e25; + border-color: #810000; + border-top-color: transparent; + border-right-color: transparent; + border-bottom-color: transparent; + border-left-color: transparent; +} + +.c0:hover { + cursor: pointer; + background-color: #fafafa; + color: #810000; +} + +.c0:hover:disabled { + cursor: not-allowed; + background-color: #fafafa; +} + +.c0:disabled { + opacity: 0.7; + background-color: #fafafa; + color: #292B3E; +} + + +`; + +exports[`it works with checked 1`] = ` +.c1 { + border-style: solid; + text-align: center; + display: inline-block; + position: relative; + font-size: 1rem; + font-weight: 500; + border-radius: 9999px; + border-width: 2px; + box-shadow: 0 2px 3px rgba(0,0,0,0.1); + padding-left: 1rem; + padding-right: 1rem; + padding-top: 0.5rem; + padding-bottom: 0.5rem; + background-color: #17a3a5; + color: white; + border-color: #17a3a5; + border-top-color: #73748b; + border-right-color: #73748b; + border-bottom-color: #73748b; + border-left-color: #73748b; +} + +.c1:hover { + cursor: pointer; + background-color: #135f61; + color: white; +} + +.c1:hover:disabled { + cursor: not-allowed; + background-color: #135f61; +} + +.c1:disabled { + opacity: 0.7; + background-color: #135f61; + color: white; +} + +.c0 { + border-style: solid; + text-align: center; + display: inline-block; + position: relative; + font-size: 1rem; + font-weight: 500; + font-family: Montserrat,sans-serif; + line-height: 2; + border-radius: 9999px; + border-width: 2px; + box-shadow: 0 2px 3px rgba(0,0,0,0.1); + padding-left: 1rem; + padding-right: 1rem; + padding-top: 0.5rem; + padding-bottom: 0.5rem; + background-color: #17a3a5; + color: white; + border-color: #17a3a5; + border-top-color: #73748b; + border-right-color: #73748b; + border-bottom-color: #73748b; + border-left-color: #73748b; +} + +.c0:hover { + cursor: pointer; + background-color: #135f61; + color: white; +} + +.c0:hover:disabled { + cursor: not-allowed; + background-color: #135f61; +} + +.c0:disabled { + opacity: 0.7; + background-color: #135f61; + color: white; +} + +.c2 { + opacity: 1; + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; +} + + +`; + +exports[`it works with checked 2`] = ` +.c2 { + opacity: 1; + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; +} + +.c1 { + border-style: solid; + text-align: center; + display: inline-block; + position: relative; + font-size: 1rem; + font-weight: 500; + border-radius: 9999px; + border-width: 2px; + box-shadow: 0 2px 3px rgba(0,0,0,0.1); + padding-left: 1rem; + padding-right: 1rem; + padding-top: 0.5rem; + padding-bottom: 0.5rem; + background-color: transparent; + color: #17a3a5; + border-color: #d4d4d4; + border-top-color: #73748b; + border-right-color: #73748b; + border-bottom-color: #73748b; + border-left-color: #73748b; +} + +.c1:hover { + cursor: pointer; + background-color: #fafafa; + color: #135f61; +} + +.c1:hover:disabled { + cursor: not-allowed; + background-color: #fafafa; +} + +.c1:disabled { + opacity: 0.7; + background-color: #fafafa; + color: #292B3E; +} + +.c0 { + border-style: solid; + text-align: center; + display: inline-block; + position: relative; + font-size: 1rem; + font-weight: 500; + font-family: Montserrat,sans-serif; + line-height: 2; + border-radius: 9999px; + border-width: 2px; + box-shadow: 0 2px 3px rgba(0,0,0,0.1); + padding-left: 1rem; + padding-right: 1rem; + padding-top: 0.5rem; + padding-bottom: 0.5rem; + background-color: transparent; + color: #17a3a5; + border-color: #d4d4d4; + border-top-color: #73748b; + border-right-color: #73748b; + border-bottom-color: #73748b; + border-left-color: #73748b; +} + +.c0:hover { + cursor: pointer; + background-color: #fafafa; + color: #135f61; +} + +.c0:hover:disabled { + cursor: not-allowed; + background-color: #fafafa; +} + +.c0:disabled { + opacity: 0.7; + background-color: #fafafa; + color: #292B3E; +} + + +`; + +exports[`it works with checked 3`] = ` +.c2 { + opacity: 1; + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; +} + +.c1 { + border-style: solid; + text-align: center; + display: inline-block; + position: relative; + font-size: 1rem; + font-weight: 500; + border-radius: 9999px; + border-width: 2px; + box-shadow: 0 2px 3px rgba(0,0,0,0.1); + padding-left: 1rem; + padding-right: 1rem; + padding-top: 0.5rem; + padding-bottom: 0.5rem; + background-color: transparent; + color: #73748b; + border-color: #fafafa; + border-top-color: #73748b; + border-right-color: #73748b; + border-bottom-color: #73748b; + border-left-color: #73748b; +} + +.c1:hover { + cursor: pointer; + background-color: #fafafa; + color: #292B3E; +} + +.c1:hover:disabled { + cursor: not-allowed; + background-color: #fafafa; +} + +.c1:disabled { + opacity: 0.7; + background-color: #fafafa; + color: #292B3E; +} + +.c0 { + border-style: solid; + text-align: center; + display: inline-block; + position: relative; + font-size: 1rem; + font-weight: 500; + font-family: Montserrat,sans-serif; + line-height: 2; + border-radius: 9999px; + border-width: 2px; + box-shadow: 0 2px 3px rgba(0,0,0,0.1); + padding-left: 1rem; + padding-right: 1rem; + padding-top: 0.5rem; + padding-bottom: 0.5rem; + background-color: transparent; + color: #73748b; + border-color: #fafafa; + border-top-color: #73748b; + border-right-color: #73748b; + border-bottom-color: #73748b; + border-left-color: #73748b; +} + +.c0:hover { + cursor: pointer; + background-color: #fafafa; + color: #292B3E; +} + +.c0:hover:disabled { + cursor: not-allowed; + background-color: #fafafa; +} + +.c0:disabled { + opacity: 0.7; + background-color: #fafafa; + color: #292B3E; +} + + +`; + +exports[`it works with checked 4`] = ` +.c2 { + opacity: 1; + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; +} + +.c1 { + border-style: solid; + text-align: center; + display: inline-block; + position: relative; + font-size: 1rem; + font-weight: 500; + border-radius: 9999px; + border-width: 2px; + box-shadow: 0 2px 3px rgba(0,0,0,0.1); + padding-left: 1rem; + padding-right: 1rem; + padding-top: 0.5rem; + padding-bottom: 0.5rem; + background-color: transparent; + color: #b41e25; + border-color: #810000; + border-top-color: #73748b; + border-right-color: #73748b; + border-bottom-color: #73748b; + border-left-color: #73748b; +} + +.c1:hover { + cursor: pointer; + background-color: #fafafa; + color: #810000; +} + +.c1:hover:disabled { + cursor: not-allowed; + background-color: #fafafa; +} + +.c1:disabled { + opacity: 0.7; + background-color: #fafafa; + color: #292B3E; +} + +.c0 { + border-style: solid; + text-align: center; + display: inline-block; + position: relative; + font-size: 1rem; + font-weight: 500; + font-family: Montserrat,sans-serif; + line-height: 2; + border-radius: 9999px; + border-width: 2px; + box-shadow: 0 2px 3px rgba(0,0,0,0.1); + padding-left: 1rem; + padding-right: 1rem; + padding-top: 0.5rem; + padding-bottom: 0.5rem; + background-color: transparent; + color: #b41e25; + border-color: #810000; + border-top-color: #73748b; + border-right-color: #73748b; + border-bottom-color: #73748b; + border-left-color: #73748b; +} + +.c0:hover { + cursor: pointer; + background-color: #fafafa; + color: #810000; +} + +.c0:hover:disabled { + cursor: not-allowed; + background-color: #fafafa; +} + +.c0:disabled { + opacity: 0.7; + background-color: #fafafa; + color: #292B3E; +} + + +`; diff --git a/src/components/toggle/index.tsx b/src/components/toggle/index.tsx new file mode 100644 index 00000000..3d167e3d --- /dev/null +++ b/src/components/toggle/index.tsx @@ -0,0 +1,34 @@ +import * as React from 'react'; +import { withTheme } from 'styled-components'; +import { mergeStyles } from '@lapidist/styles'; +import { faCircle, faDotCircle } from '@fortawesome/free-solid-svg-icons'; +import { toggleStyles } from './styles'; +import { Button, ButtonProps, ButtonPropType } from '../button'; +import { BoxProps } from '../box'; + +export * from './styles'; + +export type TogglePropType = BoxProps & ButtonProps & ButtonPropType; + +export interface ToggleProps { + readonly checked?: boolean; +} + +const BaseToggle: React.FC> = ({ + styles, + checked, + children, + ...restProps +}) => ( + +); + +export const Toggle = withTheme(BaseToggle); + +Toggle.displayName = 'Toggle'; diff --git a/src/components/toggle/styles.ts b/src/components/toggle/styles.ts new file mode 100644 index 00000000..c084b5ac --- /dev/null +++ b/src/components/toggle/styles.ts @@ -0,0 +1,19 @@ +import { Styles } from '@lapidist/styles'; +import { ToggleProps } from './index'; + +export const toggleStyles = ({ checked }: ToggleProps): Styles => + checked + ? { + borderRadius: 'rounded', + borderTopColor: { group: 'grey', shade: 'base' }, + borderRightColor: { group: 'grey', shade: 'base' }, + borderBottomColor: { group: 'grey', shade: 'base' }, + borderLeftColor: { group: 'grey', shade: 'base' } + } + : { + borderRadius: 'rounded', + borderTopColor: { group: 'base', shade: 'transparent' }, + borderRightColor: { group: 'base', shade: 'transparent' }, + borderBottomColor: { group: 'base', shade: 'transparent' }, + borderLeftColor: { group: 'base', shade: 'transparent' } + };