Skip to content

Commit

Permalink
Added Box
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusps committed Aug 23, 2019
1 parent 29daba0 commit ef2dfd4
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 67 deletions.
2 changes: 1 addition & 1 deletion src/components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import styled from 'styled-components'

import { getMeasure } from '../helpers'
import { Loader } from './Loader'
import { Clickable } from './core/Clickable'
import Clickable from './core/Clickable'

const getFontSize = (measure: Measure): number =>
getMeasure(measure, [0.8, 1, 1.25, 1.5])
Expand Down
4 changes: 2 additions & 2 deletions src/components/Form.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react'
import { Flexible } from '.'
import Flexible, { FlexibleProps } from './core/Flexible'

interface Props extends NativeFormType {
flex: FlexibleType
flex: FlexibleProps
}

const Form: React.FC<Props> = ({ flex, children, ...props }) => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/FormGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from 'react'
import styled from 'styled-components'

import { Flexible } from './core/Flexible'
import Flexible, { FlexibleProps } from './core/Flexible'

const StyledFlexible = styled(Flexible)`
padding: 0.5rem;
`

const FormGroup: React.FC<FlexibleType> = props => {
const FormGroup: React.FC<FlexibleProps> = props => {
return <StyledFlexible {...props} />
}

Expand Down
5 changes: 3 additions & 2 deletions src/components/IconButton.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { FC } from 'react'

import { Clickable, Icon } from '../index'
import { Icon } from './Icon'
import Clickable, { ClickableProps } from './core/Clickable'

interface Props extends ClickableType {
interface Props extends ClickableProps {
icon: IconType
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/Surface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import React, { FC } from 'react'
import styled from 'styled-components'

import { useTheme } from '../hooks'
import { Flexible } from './core/Flexible'
import Flexible, { FlexibleProps } from './core/Flexible'
import { useLifting } from '../hooks/useLifting'

interface Props extends FlexibleType, Liftable {}
interface Props extends FlexibleProps, Liftable {}

const StyledFlexible = styled(Flexible)<any>(props => ({
zIndex: props.zIndex,
Expand Down
3 changes: 1 addition & 2 deletions src/components/Tab.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import React, { FC, useContext } from 'react'

import { TabsContext } from '../context/TabsContext'
import { Clickable } from './core/Clickable'
import Clickable from './core/Clickable'

const Tab: FC<TabProps> = ({ id, label }) => {
const { activeTab, onTabClick } = useContext(TabsContext)
const handleClick = () => {
onTabClick(id)
}
const isActive = activeTab === id

return <Clickable onClick={handleClick}>{label}</Clickable>
}
Expand Down
7 changes: 7 additions & 0 deletions src/components/core/Box.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import styled from 'styled-components'

const Box = styled.div<any>`
box-sizing: border-box;
`

export default Box
18 changes: 13 additions & 5 deletions src/components/core/Clickable.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import React from 'react'
import styled from 'styled-components'
import Box from './Box'

const StyledButton = styled.button<any>`
const StyledBox = styled(Box)<any>`
${({ full, disabled }) => `
display: ${full ? 'block' : 'relative'};
width: ${full ? '100%' : 'auto'};
cursor: ${disabled ? 'not-allowed' : 'pointer'};
`};
border: none;
box-sizing: border-box;
overflow: hidden;
text-decoration: none;
appearance: none;
user-select: none;
background: transparent;
`

const Clickable: React.FC<ClickableType> = ({
const Clickable: React.FC<ClickableProps> = ({
full,
disabled,
onClick,
as,
...rest
}) => {
const handleClickEvent = (
Expand All @@ -30,7 +31,8 @@ const Clickable: React.FC<ClickableType> = ({
}

return (
<StyledButton
<StyledBox
as={as}
full={full}
disabled={disabled}
onClick={handleClickEvent}
Expand All @@ -41,6 +43,12 @@ const Clickable: React.FC<ClickableType> = ({

Clickable.defaultProps = {
full: false,
as: 'button',
}

export { Clickable }
export interface ClickableProps extends NativeButtonType {
full?: boolean
as?: any
}

export default Clickable
48 changes: 44 additions & 4 deletions src/components/core/Flexible.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import styled from 'styled-components'
import Box from './Box'

interface Props extends NativeDivType, FlexibleType {}

const Flexible = styled.div<Props>(props => ({
const Flexible = styled(Box)<FlexibleProps>(props => ({
width: props.width,
height: props.height,
order: props.order,
Expand Down Expand Up @@ -34,4 +33,45 @@ Flexible.defaultProps = {
content: 'stretch',
}

export { Flexible }
export interface FlexibleProps {
/** width in percentage or px */
width?: string
/** height in percentage or px */
height?: string
/** element order */
order?: number
/** element grow */
grow?: number
/** element shrink */
shrink?: number
/** flex-basis */
basis?: 'auto' | number
/** align-self */
self?: 'auto' | 'flex-start' | 'flex-end' | 'center' | 'baseline' | 'stretch'
/** if is inline-flex */
inline?: boolean
/** flex-direction */
direction?: 'row' | 'row-reverse' | 'column' | 'column-reverse'
/** flex-wrap */
wrap?: 'nowrap' | 'wrap' | 'wrap-reverse'
/** justify-content */
justify?:
| 'flex-start'
| 'flex-end'
| 'center'
| 'space-between'
| 'space-around'
| 'space-evenly'
/** align-items */
items?: 'flex-start' | 'flex-end' | 'center' | 'baseline' | 'stretch'
/** align-content */
content?:
| 'flex-start'
| 'flex-end'
| 'center'
| 'space-between'
| 'space-around'
| 'stretch'
}

export default Flexible
4 changes: 2 additions & 2 deletions src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Button } from './Button'
import { IconButton } from './IconButton'
import { Emoji } from './Emoji'
import { Clickable } from './core/Clickable'
import { Flexible } from './core/Flexible'
import Clickable from './core/Clickable'
import Flexible from './core/Flexible'
import { Loader } from './Loader'
import { Surface } from './Surface'
import { Tabs } from './Tabs'
Expand Down
45 changes: 0 additions & 45 deletions src/typings/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,51 +83,6 @@ interface Liftable {
lifting?: Measure
}

interface FlexibleType {
/** width in percentage or px */
width?: string
/** height in percentage or px */
height?: string
/** element order */
order?: number
/** element grow */
grow?: number
/** element shrink */
shrink?: number
/** flex-basis */
basis?: 'auto' | number
/** align-self */
self?: 'auto' | 'flex-start' | 'flex-end' | 'center' | 'baseline' | 'stretch'
/** if is inline-flex */
inline?: boolean
/** flex-direction */
direction?: 'row' | 'row-reverse' | 'column' | 'column-reverse'
/** flex-wrap */
wrap?: 'nowrap' | 'wrap' | 'wrap-reverse'
/** justify-content */
justify?:
| 'flex-start'
| 'flex-end'
| 'center'
| 'space-between'
| 'space-around'
| 'space-evenly'
/** align-items */
items?: 'flex-start' | 'flex-end' | 'center' | 'baseline' | 'stretch'
/** align-content */
content?:
| 'flex-start'
| 'flex-end'
| 'center'
| 'space-between'
| 'space-around'
| 'stretch'
}

interface ClickableType extends NativeButtonType {
full?: boolean
}

interface TabsContext {
activeTab: tabID
onTabClick: Function
Expand Down

0 comments on commit ef2dfd4

Please sign in to comment.