Skip to content

Commit

Permalink
feat: sleek syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
shaoruu authored and alanwu4321 committed Jun 12, 2020
1 parent 43b92a3 commit f9debe3
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 62 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ module.exports = {
'react-hooks/exhaustive-deps': 'warn',
'react/jsx-curly-newline': 'off',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'error'
'@typescript-eslint/no-unused-vars': 'error',
'func-call-spacing': 'off'
},
settings: {
react: {
Expand Down
71 changes: 35 additions & 36 deletions docs/component/dropdown.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,57 @@ route: /component/dropdown
menu: Component
---

import { Menu, MenuItem, Dropdown, Text } from 'fiber'
import { Menu, Dropdown, Text } from 'fiber'
import { Playground } from 'docz'

# Dropdown

## Hover

<Playground>
{() => {
const menu = (
<Menu>
<MenuItem>
<Text> Item 1 </Text>
</MenuItem>
<MenuItem>
<Text> Item 2 </Text>
</MenuItem>
<MenuItem>
<Text> Item 3 </Text>
</MenuItem>
</Menu>
)
{() => {
const menu = (
<Menu>
<Menu.Item>
<Text> Item 1 </Text>
</Menu.Item>
<Menu.Item>
<Text> Item 2 </Text>
</Menu.Item>
<Menu.Item>
<Text> Item 3 </Text>
</Menu.Item>
</Menu>
)
return (
<Dropdown menu={menu} trigger={"hover"} >
<Text> Hover Me </Text>
</Dropdown>
<Dropdown menu={menu} trigger={'hover'}>
<Text> Hover Me </Text>
</Dropdown>
)
}}
</Playground>

## Click

<Playground>
{() => {
const menu = (
<Menu>
<MenuItem>
<Text> Item 1 </Text>
</MenuItem>
<MenuItem>
<Text> Item 2 </Text>
</MenuItem>
<MenuItem>
<Text> Item 3 </Text>
</MenuItem>
</Menu>
)
{() => {
const menu = (
<Menu>
<MenuItem>
<Text> Item 1 </Text>
</MenuItem>
<MenuItem>
<Text> Item 2 </Text>
</MenuItem>
<MenuItem>
<Text> Item 3 </Text>
</MenuItem>
</Menu>
)
return (
<Dropdown menu={menu} trigger={"click"} >
<button> Click Me </button>
</Dropdown>
<Dropdown menu={menu} trigger={'click'}>
<button> Click Me </button>
</Dropdown>
)
}}
</Playground>

2 changes: 1 addition & 1 deletion src/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const Wrapper = styled.div<any>`
`

const Dropdown: FC<DropdownProps> = ({ menu, trigger, children, ...props }) => {
const node = useRef<{ contains:(e: EventTarget) => Boolean }>(null)
const node = useRef<{ contains: (e: EventTarget) => Boolean }>(null)
const [expand, setExpand] = useState(false)

const handleClick = (e: Event) => {
Expand Down
16 changes: 8 additions & 8 deletions src/Dropdown/__tests__/Dropdown.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Dropdown, Menu, MenuItem, Text } from '../../'
import { Dropdown, Menu, Text } from '../../'

import React from 'react'
import { render } from 'test/utils'
Expand All @@ -7,22 +7,22 @@ describe('Menu & Menu Items', () => {
it('renders correctly', () => {
const menu = (
<Menu>
<MenuItem>
<Menu.Item>
<Text> Item 1 </Text>
</MenuItem>
<MenuItem>
</Menu.Item>
<Menu.Item>
<Text> Item 2 </Text>
</MenuItem>
<MenuItem>
</Menu.Item>
<Menu.Item>
<Text> Item 3 </Text>
</MenuItem>
</Menu.Item>
</Menu>
)

const dropdown = render(
<Dropdown menu={menu} trigger='hover'>
<Text> Hover Me </Text>
</Dropdown >
</Dropdown>
)

expect(dropdown).toMatchSnapshot()
Expand Down
12 changes: 8 additions & 4 deletions src/Menu/Menu.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@

import { StyleProps, styleComposition } from '../utils/styles'
import { withProperties } from '../utils'

import { MenuItem } from './MenuItem'

import styled from 'styled-components'

export interface MenuProps extends StyleProps { }
export interface MenuProps extends StyleProps {}

const Menu = styled.div<MenuProps>`
const MenuWrapper = styled.div<MenuProps>`
${styleComposition}
position: absolute;
z-index: 999;
min-width: 160px;
background-color: #f9f9f9;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
`

const Menu = withProperties(MenuWrapper, { Item: MenuItem })

export { Menu }
14 changes: 7 additions & 7 deletions src/Menu/__tests__/Menu.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Menu, MenuItem, Text } from '../../'
import { Menu, Text } from '../../'

import React from 'react'
import { render } from 'test/utils'
Expand All @@ -7,15 +7,15 @@ describe('Menu & Menu Items', () => {
it('renders correctly', () => {
const menu = render(
<Menu>
<MenuItem>
<Menu.Item>
<Text> Item 1 </Text>
</MenuItem>
<MenuItem>
</Menu.Item>
<Menu.Item>
<Text> Item 2 </Text>
</MenuItem>
<MenuItem>
</Menu.Item>
<Menu.Item>
<Text> Item 3 </Text>
</MenuItem>
</Menu.Item>
</Menu>
)

Expand Down
8 changes: 4 additions & 4 deletions src/Menu/__tests__/__snapshots__/Menu.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

exports[`Menu & Menu Items renders correctly 1`] = `
<div
className="sc-AxheI eXThOJ"
className="sc-Axmtr AYONq"
>
<a
className="sc-Axmtr cHRaGC"
className="sc-AxheI cFvGuJ"
>
<span
className="sc-AxiKw fhcQjA"
Expand All @@ -15,7 +15,7 @@ exports[`Menu & Menu Items renders correctly 1`] = `
</span>
</a>
<a
className="sc-Axmtr cHRaGC"
className="sc-AxheI cFvGuJ"
>
<span
className="sc-AxiKw fhcQjA"
Expand All @@ -25,7 +25,7 @@ exports[`Menu & Menu Items renders correctly 1`] = `
</span>
</a>
<a
className="sc-Axmtr cHRaGC"
className="sc-AxheI cFvGuJ"
>
<span
className="sc-AxiKw fhcQjA"
Expand Down
1 change: 0 additions & 1 deletion src/Menu/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './Menu'
export * from './MenuItem'
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './typeHelper'
6 changes: 6 additions & 0 deletions src/utils/typeHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function withProperties<A, B>(component: A, properties: B): A & B {
Object.keys(properties).forEach((key) => {
component[key] = properties[key]
})
return component as A & B
}

0 comments on commit f9debe3

Please sign in to comment.