-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes #280 This PR adds the DataGrid & DatePicker components from Pro
- Loading branch information
1 parent
44416cf
commit d9c4410
Showing
58 changed files
with
25,564 additions
and
139 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 @@ | ||
export * from './data-grid' |
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
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
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,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> | ||
) | ||
} |
Oops, something went wrong.