Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
fnhipster committed Apr 23, 2020
1 parent d293729 commit a8b24c9
Show file tree
Hide file tree
Showing 48 changed files with 208 additions and 852 deletions.
12 changes: 12 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## file extensions
*.*
!*.css
!*.js
!*.json
!*.jsx
!*.less
!*.md
!*.mdx
!*.ts
!*.tsx
!*.yml
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"semi": false,
"singleQuote": true,
"jsxBracketSameLine": false,
"printWidth": 120,
"printWidth": 200,
"arrowParens": "avoid"
}
2 changes: 1 addition & 1 deletion bin/lib/new-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const templateStory = require('../templates/components/Component.story')
const templateIndex = require('../templates/components/index')

module.exports = (name, folder = 'components') => {
if (! /^[A-Z][a-z]+(?:[A-Z][a-z]+)*$/.test(name)) {
if (!/^[A-Z][a-z]+(?:[A-Z][a-z]+)*$/.test(name)) {
console.error(`⚠️ \x1b[4m${name} \x1b[0mis not a valid component name. Try naming your component with pascal case. i.e. \x1b[4mNewComponent\x1b[0m`)
return null
}
Expand Down
9 changes: 4 additions & 5 deletions bin/lib/writeFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ const fs = require('fs')

module.exports = function writeFile(filePath, content) {
const relativePath = path.relative('.', filePath)
if ( fs.existsSync(filePath) ) {
console.log(`💥 \x1b[31m${relativePath} \x1b[0malready exists`)
}
else {
if (fs.existsSync(filePath)) {
console.log(`💥 \x1b[31m${relativePath} \x1b[0malready exists`)
} else {
fs.writeFileSync(filePath, content)
console.log(`👌 \x1b[32m${relativePath} \x1b[0mcreated`)
console.log(`👌 \x1b[32m${relativePath} \x1b[0mcreated`)
}
}
3 changes: 2 additions & 1 deletion bin/templates/components/Component.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const source = require('common-tags').source

module.exports = (Name) => source`
module.exports = Name =>
source`
import React from 'react'
import { Component } from '../../lib'
Expand Down
3 changes: 2 additions & 1 deletion bin/templates/components/Component.styled.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const source = require('common-tags').source

module.exports = () => source`
module.exports = () =>
source`
import styled from 'styled-components'
export const Root = styled.div\`
Expand Down
6 changes: 1 addition & 5 deletions components/Accordion/Accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ type CompoundComponent = {
Item: Component<AccordionItemProps>
}

export const Accordion: Component<AccordionProps> & CompoundComponent = ({
children,
defaultSelected = -1,
...props
}) => {
export const Accordion: Component<AccordionProps> & CompoundComponent = ({ children, defaultSelected = -1, ...props }) => {
const [selected, setSelected] = useState(defaultSelected)

/** Update Selected when prop changes */
Expand Down
8 changes: 1 addition & 7 deletions components/Breadcrumbs/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@ export type BreadcrumbsProps = {
>
}

export const Breadcrumbs: Component<BreadcrumbsProps> = ({
loading,
divider = '',
items = [],
prefix = '',
...props
}) => {
export const Breadcrumbs: Component<BreadcrumbsProps> = ({ loading, divider = '', items = [], prefix = '', ...props }) => {
return (
<Root {...props}>
{loading ? (
Expand Down
11 changes: 1 addition & 10 deletions components/BubbleCarousel/BubbleCarousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,7 @@ export const BubbleCarousel: Component<BubbleCarouselProps> = ({ children, loadi
const [scrollerRef, setScrollerRef] = useState<MutableRefObject<Element>>()

return (
<Root
as={Carousel}
scrollerRef={setScrollerRef}
gap={1.4}
show="auto"
padding={1.5}
snap={false}
hideScrollBar
{...props}
>
<Root as={Carousel} scrollerRef={setScrollerRef} gap={1.4} show="auto" padding={1.5} snap={false} hideScrollBar {...props}>
{loading ? (
<>
<CarouselItem>
Expand Down
9 changes: 1 addition & 8 deletions components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,7 @@ export type ButtonProps = Props<{
loading?: LoaderProps
}>

export const Button: Component<ButtonProps> = ({
text,
children = text,
loading,
secondary = false,
outline = false,
...props
}) => {
export const Button: Component<ButtonProps> = ({ text, children = text, loading, secondary = false, outline = false, ...props }) => {
return (
<Root $secondary={secondary} $outline={outline} as="button" {...props} disabled={!!loading || props.disabled}>
{!!loading ? <Loader as="span" {...loading} /> : <span>{children}</span>}
Expand Down
8 changes: 1 addition & 7 deletions components/Carousel/Carousel.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@ const Item = styled.div`
`

storiesOf('📦 Components/Carousel', module).add('Default', () => (
<Carousel
padding={number('padding', 4)}
gap={number('gap', 2)}
show={number('show', 1)}
hideScrollBar={boolean('hideScrollBar', false)}
snap={boolean('snap', true)}
>
<Carousel padding={number('padding', 4)} gap={number('gap', 2)} show={number('show', 1)} hideScrollBar={boolean('hideScrollBar', false)} snap={boolean('snap', true)}>
<Carousel.Item>
<Item>1</Item>
</Carousel.Item>
Expand Down
3 changes: 1 addition & 2 deletions components/Carousel/Carousel.styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ export const Scroller = styled.div<{
-webkit-overflow-scrolling: touch;
display: grid;
grid-auto-columns: ${props =>
props.$show === 'auto' ? 'max-content' : 'calc(100% / var(--show) - var(--padding))'};
grid-auto-columns: ${props => (props.$show === 'auto' ? 'max-content' : 'calc(100% / var(--show) - var(--padding))')};
grid-auto-flow: column;
grid-gap: var(--gap);
overflow-x: scroll;
Expand Down
21 changes: 2 additions & 19 deletions components/Carousel/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,7 @@ type CompoundComponent = {
Item: Component<CarouselItemProps>
}

export const Carousel: Component<CarouselProps> & CompoundComponent = ({
children,
gap = 0,
padding = 0,
show = 1,
hideScrollBar = false,
snap = true,
scrollerRef,
...props
}) => {
export const Carousel: Component<CarouselProps> & CompoundComponent = ({ children, gap = 0, padding = 0, show = 1, hideScrollBar = false, snap = true, scrollerRef, ...props }) => {
const rootElemRef = useRef(null)
const scrollerElemRef = useRef(null)
const { height } = useMeasure(rootElemRef)
Expand All @@ -40,15 +31,7 @@ export const Carousel: Component<CarouselProps> & CompoundComponent = ({

return (
<Root ref={rootElemRef} $height={!hideScrollBar ? height : undefined}>
<Scroller
ref={scrollerElemRef}
$padding={childrenCount > 1 ? padding : 0}
$show={show}
$gap={gap}
$hideScrollBar={hideScrollBar}
$snap={snap}
{...props}
>
<Scroller ref={scrollerElemRef} $padding={childrenCount > 1 ? padding : 0} $show={show} $gap={gap} $hideScrollBar={hideScrollBar} $snap={snap} {...props}>
{children}
</Scroller>
</Root>
Expand Down
24 changes: 2 additions & 22 deletions components/CartList/CartList.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
import React from 'react'
import { Component, Props } from '../../lib'
import {
Root,
Product,
Thumbnail,
DetailsWrapper,
Title,
Price,
Quantity,
Sku,
Options,
Option,
OptionLabel,
OptionValue,
} from './CartList.styled'
import { Root, Product, Thumbnail, DetailsWrapper, Title, Price, Quantity, Sku, Options, Option, OptionLabel, OptionValue } from './CartList.styled'
import PriceComponent, { PriceProps } from '../Price'
import Image, { ImageProps } from '../Image'
import QuantityComponent, { QuantityProps } from '../Quantity'
Expand Down Expand Up @@ -47,14 +34,7 @@ export const CartList: Component<CartListProps> = ({ loading, items, children, .
{items?.map(({ _id, title, sku, thumbnail, price, quantity, options }, index) => (
<Product key={_id || index}>
<Thumbnail>
<Image
vignette={8}
transition
width="100%"
height="auto"
lazyload={{ offsetY: 100 }}
{...thumbnail}
/>
<Image vignette={8} transition width="100%" height="auto" lazyload={{ offsetY: 100 }} {...thumbnail} />
</Thumbnail>
<DetailsWrapper>
<Title {...title}>{title.text}</Title>
Expand Down
6 changes: 1 addition & 5 deletions components/CartSummary/CartSummary.styled.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import styled from 'styled-components'
import {
Button as AccordionButton,
Content as AccordionContent,
ButtonLabel as AccordionLabel,
} from '../Accordion/Accordion.styled'
import { Button as AccordionButton, Content as AccordionContent, ButtonLabel as AccordionLabel } from '../Accordion/Accordion.styled'

export const Root = styled.div`
display: grid;
Expand Down
10 changes: 1 addition & 9 deletions components/Checkout/ApplyCouponForm/ApplyCouponForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,7 @@ export type ApplyCouponFormProps = FormProps<ApplyCouponFormPayload> & {
error?: string
}

export const ApplyCouponForm: Component<ApplyCouponFormProps> = ({
field,
loading = false,
onSubmit,
submitButton,
submitting = false,
error,
...props
}) => {
export const ApplyCouponForm: Component<ApplyCouponFormProps> = ({ field, loading = false, onSubmit, submitButton, submitting = false, error, ...props }) => {
return (
<Root as={Form} onSubmit={onSubmit} {...props}>
<Input loading={loading} rules={{ required: true }} disabled={submitting} error={error} {...field} />
Expand Down
41 changes: 4 additions & 37 deletions components/Checkout/ContactInfoForm/ContactInfoForm.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
import React, { useCallback } from 'react'
import { Component } from '../../../lib'
import {
Root,
Email,
FirstName,
LastName,
Company,
Address1,
Address2,
City,
Country,
Region,
PostalCode,
PhoneNumber,
} from './ContactInfoForm.styled'
import { Root, Email, FirstName, LastName, Company, Address1, Address2, City, Country, Region, PostalCode, PhoneNumber } from './ContactInfoForm.styled'

import Form, { FormProps, Input, InputProps, Select, SelectProps, FormError, patterns } from '../../Form'
import Button, { ButtonProps } from '../../Button'
Expand Down Expand Up @@ -56,18 +43,7 @@ export type ContactInfoFormProps = FormProps<ContactInfoFormPayload> & {
error?: string
}

export const ContactInfoForm: Component<ContactInfoFormProps> = ({
edit = false,
fields,
submitButton,
editButton,
onSubmit,
onEdit,
loading,
submitting,
error,
...props
}) => {
export const ContactInfoForm: Component<ContactInfoFormProps> = ({ edit = false, fields, submitButton, editButton, onSubmit, onEdit, loading, submitting, error, ...props }) => {
const handleOnClickEdit = useCallback(
(e: Event) => {
e.preventDefault()
Expand All @@ -84,12 +60,7 @@ export const ContactInfoForm: Component<ContactInfoFormProps> = ({
<Form autoComplete={props.disabled ? 'off' : 'on'} onSubmit={onSubmit} {...props}>
<Root $preview={!edit}>
<Email>
<Input
loading={loading}
rules={{ required: true, pattern: patterns.email }}
disabled={disabled}
{...email}
/>
<Input loading={loading} rules={{ required: true, pattern: patterns.email }} disabled={disabled} {...email} />
</Email>
<FirstName>
<Input loading={loading} rules={{ required: true }} disabled={disabled} {...firstName} />
Expand Down Expand Up @@ -129,11 +100,7 @@ export const ContactInfoForm: Component<ContactInfoFormProps> = ({

{error && <FormError>{error}</FormError>}

{edit ? (
<Button type="submit" loading={loading || submitting} {...submitButton} />
) : (
<Button type="button" outline onClick={handleOnClickEdit} {...editButton} />
)}
{edit ? <Button type="submit" loading={loading || submitting} {...submitButton} /> : <Button type="button" outline onClick={handleOnClickEdit} {...editButton} />}
</Form>
)
}
25 changes: 5 additions & 20 deletions components/Checkout/PaymentMethodForm/PaymentMethodForm.styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,14 @@ export const Root = styled.div`
display: none;
}
&
.braintree-sheet__content--form
.braintree-form__field-group
.braintree-form__field
.braintree-form__hosted-field {
& .braintree-sheet__content--form .braintree-form__field-group .braintree-form__field .braintree-form__hosted-field {
border-top: none;
border-left: none;
border-right: none;
border-bottom: 0.1rem solid ${props => props.theme.colors.primary25};
}
&
.braintree-sheet__content--form
.braintree-form__field-group.braintree-form__field-group--has-error
.braintree-form__field
.braintree-form__hosted-field {
& .braintree-sheet__content--form .braintree-form__field-group.braintree-form__field-group--has-error .braintree-form__field .braintree-form__hosted-field {
border-bottom-color: ${props => props.theme.colors.error};
}
Expand Down Expand Up @@ -63,16 +55,9 @@ export const Root = styled.div`
color: ${props => props.theme.colors.onSurface};
}
&
.braintree-sheet__content--form
.braintree-form__field-group.braintree-form__field-group--card-type-known
.braintree-form__field-secondary-icon,
.braintree-sheet__content--form
.braintree-form__field-group.braintree-form__field-group--has-error
.braintree-form__field-error-icon,
.braintree-sheet__content--form
.braintree-form__field-group.braintree-form__field-group--is-focused
.braintree-form__field-secondary-icon {
& .braintree-sheet__content--form .braintree-form__field-group.braintree-form__field-group--card-type-known .braintree-form__field-secondary-icon,
.braintree-sheet__content--form .braintree-form__field-group.braintree-form__field-group--has-error .braintree-form__field-error-icon,
.braintree-sheet__content--form .braintree-form__field-group.braintree-form__field-group--is-focused .braintree-form__field-secondary-icon {
display: none;
}
`
Expand Down
16 changes: 2 additions & 14 deletions components/Checkout/PaymentMethodForm/PaymentMethodForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,7 @@ const reducer: Reducer<ReducerState, ReducerActions> = (state, action) => {
}
}

export const PaymentMethodForm: Component<PaymentMethodFormProps> = ({
submitting,
error,
braintree,
submitButton,
editButton,
onSubmit,
...props
}) => {
export const PaymentMethodForm: Component<PaymentMethodFormProps> = ({ submitting, error, braintree, submitButton, editButton, onSubmit, ...props }) => {
const { colors } = useTheme()

const containerElem = useRef(null)
Expand Down Expand Up @@ -218,11 +210,7 @@ export const PaymentMethodForm: Component<PaymentMethodFormProps> = ({

{(error || formError) && <FormError>{error || formError}</FormError>}

{submitting || loading || editable ? (
<Button type="submit" loading={submitting || loading} {...submitButton} />
) : (
<Button outline onClick={handleOnEdit} {...editButton} />
)}
{submitting || loading || editable ? <Button type="submit" loading={submitting || loading} {...submitButton} /> : <Button outline onClick={handleOnEdit} {...editButton} />}
</Root>
)
}
Loading

0 comments on commit a8b24c9

Please sign in to comment.