-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #440 from kufu/fix-base
Extend Base component
- Loading branch information
Showing
3 changed files
with
40 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,26 @@ | ||
import * as React from 'react' | ||
import React, { ReactNode, forwardRef } from 'react' | ||
import styled, { css } from 'styled-components' | ||
|
||
type Radius = 's' | 'm' | ||
|
||
interface Props { | ||
radius?: Radius | ||
children?: React.ReactNode | ||
type Props = { | ||
children: ReactNode | ||
radius?: 's' | 'm' | ||
className?: string | ||
} | ||
|
||
const BaseComponent: React.FC<Props> = ({ radius = 'm', children, className = '' }) => { | ||
export const Base = forwardRef<HTMLDivElement, Props>(({ radius = 'm', ...props }, ref) => { | ||
const radiusMap = { | ||
s: '6px', | ||
m: '8px', | ||
} | ||
return <Wrapper radius={radiusMap[radius]} ref={ref} {...props} /> | ||
}) | ||
|
||
return ( | ||
<Wrapper radius={radiusMap[radius]} className={className}> | ||
{children} | ||
</Wrapper> | ||
) | ||
} | ||
|
||
interface WrapperProps { | ||
radius: string | ||
} | ||
|
||
const Wrapper = styled.div` | ||
${({ radius }: WrapperProps) => { | ||
const Wrapper = styled.div<{ radius: string }>` | ||
${({ radius }) => { | ||
return css` | ||
border-radius: ${radius}; | ||
box-shadow: rgba(51, 51, 51, 0.3) 1px 1px 4px 0; | ||
overflow: hidden; | ||
background-color: #fff; | ||
` | ||
}} | ||
` | ||
|
||
export const Base = BaseComponent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Base | ||
|
||
```tsx | ||
import { Base } from 'smarthr-ui' | ||
|
||
<Base radius="m">text</Base> | ||
``` | ||
|
||
## props | ||
|
||
| Name | Required | Type | DefaultValue | Description | | ||
| ------ | -------- | ------------------------------ | ------------ | ------------------- | | ||
| radius | - | **string** <br> 's' | 'm' | 'm' | border-radius size. | |