Skip to content

Commit

Permalink
feat: DataGrid & DatePicker (#281)
Browse files Browse the repository at this point in the history
closes #280 

This PR adds the DataGrid & DatePicker components from Pro
  • Loading branch information
joduplessis authored Jul 22, 2024
1 parent 44416cf commit d9c4410
Show file tree
Hide file tree
Showing 58 changed files with 25,564 additions and 139 deletions.
20,945 changes: 20,945 additions & 0 deletions dummy-data/data-grid.tsx

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dummy-data/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './data-grid'
64 changes: 48 additions & 16 deletions packages/core/src/button/button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export const Usage = () => <Button>Okay</Button>
// --

export const Sizes = () => (
<Stack spacing={5} wrap="wrap">
<Stack
spacing={5}
wrap="wrap">
<Button size="xs">Xsmall</Button>
<Button size="sm">Small</Button>
<Button size="md">Medium</Button>
Expand All @@ -51,7 +53,9 @@ export const NormalVariants = () => (
gap="1rem"
alignItems="flex-start">
<Heading as="h5">Normal</Heading>
<Stack spacing={5} wrap="wrap">
<Stack
spacing={5}
wrap="wrap">
<Button>Default</Button>
<Button variant="accent">Accent</Button>
<Button variant="success">Success</Button>
Expand All @@ -62,7 +66,9 @@ export const NormalVariants = () => (
<Button variant="highlight">Highlight</Button>
</Stack>
<Heading as="h5">Disabled</Heading>
<Stack spacing={5} wrap="wrap">
<Stack
spacing={5}
wrap="wrap">
<Button disabled>Default</Button>
<Button
disabled
Expand Down Expand Up @@ -101,7 +107,9 @@ export const NormalVariants = () => (
</Button>
</Stack>
<Heading as="h5">Loading</Heading>
<Stack spacing={5} wrap="wrap">
<Stack
spacing={5}
wrap="wrap">
<Button loading>Default</Button>
<Button
loading
Expand Down Expand Up @@ -140,7 +148,9 @@ export const NormalVariants = () => (
</Button>
</Stack>
<Heading as="h5">Active</Heading>
<Stack spacing={5} wrap="wrap">
<Stack
spacing={5}
wrap="wrap">
<Button active>Default</Button>
<Button
active
Expand Down Expand Up @@ -189,7 +199,9 @@ export const SubtleVariants = () => (
gap="1rem"
alignItems="flex-start">
<Heading as="h5">Normal</Heading>
<Stack spacing={5} wrap="wrap">
<Stack
spacing={5}
wrap="wrap">
<Button subtle>Default</Button>
<Button
subtle
Expand Down Expand Up @@ -228,7 +240,9 @@ export const SubtleVariants = () => (
</Button>
</Stack>
<Heading as="h5">Disabled</Heading>
<Stack spacing={5} wrap="wrap">
<Stack
spacing={5}
wrap="wrap">
<Button
subtle
disabled>
Expand Down Expand Up @@ -278,7 +292,9 @@ export const SubtleVariants = () => (
</Button>
</Stack>
<Heading as="h5">Loading</Heading>
<Stack spacing={5} wrap="wrap">
<Stack
spacing={5}
wrap="wrap">
<Button
subtle
loading>
Expand Down Expand Up @@ -328,7 +344,9 @@ export const SubtleVariants = () => (
</Button>
</Stack>
<Heading as="h5">Active</Heading>
<Stack spacing={5} wrap="wrap">
<Stack
spacing={5}
wrap="wrap">
<Button
subtle
active>
Expand Down Expand Up @@ -388,7 +406,9 @@ export const OutlineVariants = () => (
gap="1rem"
alignItems="flex-start">
<Heading as="h5">Normal</Heading>
<Stack spacing={5} wrap="wrap">
<Stack
spacing={5}
wrap="wrap">
<Button outline>Default</Button>
<Button
outline
Expand Down Expand Up @@ -427,7 +447,9 @@ export const OutlineVariants = () => (
</Button>
</Stack>
<Heading as="h5">Disabled</Heading>
<Stack spacing={5} wrap="wrap">
<Stack
spacing={5}
wrap="wrap">
<Button
outline
disabled>
Expand Down Expand Up @@ -477,7 +499,9 @@ export const OutlineVariants = () => (
</Button>
</Stack>
<Heading as="h5">Loading</Heading>
<Stack spacing={5} wrap="wrap">
<Stack
spacing={5}
wrap="wrap">
<Button
outline
loading>
Expand Down Expand Up @@ -527,7 +551,9 @@ export const OutlineVariants = () => (
</Button>
</Stack>
<Heading as="h5">Active</Heading>
<Stack spacing={5} wrap="wrap">
<Stack
spacing={5}
wrap="wrap">
<Button
outline
active>
Expand Down Expand Up @@ -582,7 +608,9 @@ export const OutlineVariants = () => (
// --

export const WithPrefixAndSuffix = () => (
<Stack spacing={5} wrap="wrap">
<Stack
spacing={5}
wrap="wrap">
<Button
as="a"
href="https://google.com"
Expand Down Expand Up @@ -623,7 +651,9 @@ export const EllipsisMode = () => (
// --

export const AsLink = () => (
<Stack spacing={5} wrap="wrap">
<Stack
spacing={5}
wrap="wrap">
<Button
as="a"
href="https://google.com"
Expand Down Expand Up @@ -701,7 +731,9 @@ export const AsLink = () => (
// --

export const WithIcon = () => (
<Stack spacing={5} wrap="wrap">
<Stack
spacing={5}
wrap="wrap">
<IconButton
icon="bin"
size="xs"
Expand Down
8 changes: 6 additions & 2 deletions packages/core/src/carousel/carousel.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export const Usage = () => {
const { current, setCurrent } = useCarousel(0)

return (
<View width="100%" style={{ maxWidth: 500 }}>
<View
width="100%"
style={{ maxWidth: 500 }}>
<Carousel
width="100%"
height={400}
Expand Down Expand Up @@ -178,7 +180,9 @@ export const ImageGallery = () => {
const { current, setCurrent } = useCarousel(0)

return (
<View width="100%" style={{ maxWidth: 500 }}>
<View
width="100%"
style={{ maxWidth: 500 }}>
<Carousel
width="100%"
height={400}
Expand Down
9 changes: 3 additions & 6 deletions packages/core/src/copy/copy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ import { CoreViewProps, Size } from '../types'
export const useCopy = () => {
const copyToClipboard = (value: any) => {
try {
navigator
.clipboard
.writeText(value)
.catch(err => {
throw new Error(err)
})
navigator.clipboard.writeText(value).catch((err) => {
throw new Error(err)
})
} catch (err) {
const tempInput: any = documentObject.createElement('textarea')
tempInput.style = 'position: absolute; left: -1000px; top: -1000px;'
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/cropper/cropper.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export const docs = {

export const Usage = () => (
<View
width="100%"
style={{ maxWidth: 500 }}
width="100%"
style={{ maxWidth: 500 }}
height={400}>
<Cropper
src="/photos/01.jpg"
Expand Down
81 changes: 81 additions & 0 deletions packages/core/src/data-grid/data-grid-cell-component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { IconLib, Text, addAlpha, classNames, cleanObject, getForegroundColor, getKey, shadeColor } from '../'
import React, { useEffect, useMemo, useRef, useState } from 'react'

export type DataGridCellComponentProps = {
value: string | number
options?: any
icon?: string
color?: string
edit?: boolean
onEdit: (value) => void
onCancel: () => void
}

export const DataGridCellComponent = (props: DataGridCellComponentProps) => {
const { value, options = {}, icon, color, edit, onEdit, onCancel } = props
const ref = useRef(null)
const inputRef = useRef(null)
const [text, setText] = useState(value)
const styles = useMemo(() => {
const foregroundColor = color ? color : null
const backgroundColor = color ? addAlpha(color, 0.1) : null
return cleanObject({
color: foregroundColor,
backgroundColor,
})
}, [color])
const className = classNames({
'f-data-grid-cell-component': true,
'f-row': true,
'is-edit': edit,
'is-color': !!color,
})

const handleKeyDown = (e: any) => {
const { isEnter, isEscape } = getKey(e)
if (isEnter) onEdit(text)
if (isEscape) onCancel()
}

useEffect(() => {
setText(value)
}, [value])

useEffect(() => {
inputRef.current.select()
}, [edit])

return (
<div
style={styles}
ref={ref}
className={className}>
{!edit && (
<>
<Text
as="span"
className="f-ellipsis f-flexer">
{value}
</Text>

{!!icon && (
<IconLib
size="sm"
icon={icon}
/>
)}
</>
)}

<input
ref={inputRef}
style={{ display: edit ? 'block' : 'none' }}
type="text"
value={text}
onBlur={() => onEdit(text)}
onKeyDown={handleKeyDown}
onChange={(e) => setText(e.target.value)}
/>
</div>
)
}
Loading

0 comments on commit d9c4410

Please sign in to comment.