Skip to content

Commit

Permalink
Refactor Sidesheet to typescript. (#706)
Browse files Browse the repository at this point in the history
  • Loading branch information
joelmheim authored and vnys committed Nov 13, 2020
1 parent 6136281 commit 92f139c
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 98 deletions.
95 changes: 0 additions & 95 deletions libraries/core-react/src/SideSheet/SideSheet.jsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-undef */
import React from 'react'
import { render, cleanup } from '@testing-library/react'
import '@testing-library/jest-dom'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-nocheck
import { tokens } from '@equinor/eds-tokens'

const {
Expand Down
94 changes: 94 additions & 0 deletions libraries/core-react/src/SideSheet/SideSheet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import React, { forwardRef } from 'react'
import PropTypes from 'prop-types'
import styled from 'styled-components'
import { clear } from '@equinor/eds-icons'
import { spacingsTemplate } from '../_common/templates'
import { Typography } from '../Typography'
import { Button } from '../Button'
import { Icon } from '../Icon'
import { sidesheet as tokens } from './SideSheet.tokens'

const icons = {
clear,
}

Icon.add(icons)

const { background, spacings, border } = tokens

type StyleProps = {
width: string
}

type Props = {
/** Title for Side Sheet */
title?: string
/** Variant controls width of Side Sheet */
variant?: 'small' | 'medium' | 'large' | 'xlarge'
/** OnClick function (close) */
onClose?: (Event) => void
/** Open / close Side Sheet */
open?: boolean
} & React.HTMLAttributes<HTMLDivElement>

const StyledSideSheet = styled.div<StyleProps>`
height: 100%;
position: absolute;
z-index: 1;
top: 0;
right: 0;
box-sizing: border-box;
border-left: ${border.left.width} solid ${border.left.color};
background: ${background};
width: ${({ width }) => width};
${spacingsTemplate(spacings)};
`

const Header = styled.div`
display: flex;
flex-wrap: nowrap;
justify-content: space-between;
align-items: center;
padding-bottom: 24px;
padding-right: 10px;
`

export const SideSheet = forwardRef<HTMLDivElement, Props>(
function EdsSideSheet(
{
variant = 'medium',
title = '',
children,
className = '',
open = true,
onClose,
...rest
},
ref,
) {
const props = {
...rest,
className,
ref,
width: tokens.width[variant],
}

// Controller must set open={false} when pressing the close button
return (
open && (
<StyledSideSheet {...props} id="side-sheet">
<Header>
<Typography variant="h2">{title}</Typography>
<Button variant="ghost_icon" onClick={onClose} title="Close">
<Icon name="clear" title="Close" />
</Button>
</Header>
{children}
</StyledSideSheet>
)
)
},
)

SideSheet.displayName = 'eds-sidesheet'
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
// @ts-nocheck
export { SideSheet } from './SideSheet'

0 comments on commit 92f139c

Please sign in to comment.