-
Notifications
You must be signed in to change notification settings - Fork 119
feat(textarea,data-grid): interactive elements and controlled height #4291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
90d3da5
feat(textarea,data-grid): add support for interactive elements and co…
krisantrobus 961f047
chore(ci): typedocs, lint
krisantrobus d4b4582
feat(docs-textarea): made a note of minRows
krisantrobus 2f4f319
fix(docs): incorrect story link
krisantrobus 3a25f57
fix(docs): usage for Textarea
krisantrobus a3fd875
Merge branch 'main' into fix-data-grid-focus
kodiakhq[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,6 @@ | ||
--- | ||
"@twilio-paste/data-grid": patch | ||
"@twilio-paste/core": patch | ||
--- | ||
|
||
[DataGridCell] reworked the click events triggered to allow interactive elements to correctly pull focus |
This file contains hidden or 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,6 @@ | ||
--- | ||
"@twilio-paste/textarea": minor | ||
"@twilio-paste/core": minor | ||
--- | ||
|
||
[TextArea] exposed a prop to allow the minRows to be configured effectively setting the min height |
This file contains hidden or 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 hidden or 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
120 changes: 120 additions & 0 deletions
120
packages/paste-core/components/data-grid/stories/components/FixedCellHeights.tsx
This file contains hidden or 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,120 @@ | ||
import { Box } from "@twilio-paste/box"; | ||
import { EditableCodeBlock } from "@twilio-paste/editable-code-block"; | ||
import { MoreIcon } from "@twilio-paste/icons/esm/MoreIcon"; | ||
import { Menu, MenuButton, MenuItem, MenuSeparator, useMenuState } from "@twilio-paste/menu"; | ||
import { Option, Select } from "@twilio-paste/select"; | ||
import { TextArea } from "@twilio-paste/textarea"; | ||
import * as React from "react"; | ||
import type { JSX } from "react"; | ||
|
||
import { DataGrid, DataGridBody, DataGridCell, DataGridHead, DataGridHeader, DataGridRow } from "../../src"; | ||
import { TableBodyData, TableHeaderData } from "./constants"; | ||
|
||
const ActionMenu = (): JSX.Element => { | ||
const menu = useMenuState(); | ||
return ( | ||
<Box display="flex" justifyContent="center"> | ||
<MenuButton {...menu} variant="reset" size="reset"> | ||
<MoreIcon decorative={false} title="More options" /> | ||
</MenuButton> | ||
<Menu {...menu} aria-label="Preferences"> | ||
<MenuItem {...menu} href="https://google.com"> | ||
Settings | ||
</MenuItem> | ||
<MenuItem {...menu} disabled> | ||
Extensions | ||
</MenuItem> | ||
<MenuSeparator {...menu} /> | ||
<MenuItem {...menu}>Keyboard shortcuts</MenuItem> | ||
</Menu> | ||
</Box> | ||
); | ||
}; | ||
|
||
const InputCell: React.FC<{ colIndex: number; rowIndex: number; value: string | null }> = ({ | ||
colIndex, | ||
rowIndex, | ||
value: originalValue, | ||
}): JSX.Element => { | ||
const [value, setValue] = React.useState<string | null>(originalValue); | ||
return ( | ||
<DataGridCell key={`col-${colIndex}`}> | ||
<TextArea | ||
aria-label={TableHeaderData[colIndex]} | ||
data-testid={`input-${rowIndex}-${colIndex}`} | ||
value={value || ""} | ||
onChange={(change) => { | ||
setValue(change.target.value); | ||
}} | ||
maxRows={6} | ||
minRows={6} | ||
id={`text-area-${rowIndex}-${colIndex}`} | ||
/> | ||
</DataGridCell> | ||
); | ||
}; | ||
|
||
export const FixedCellHeightDataGrid = (): JSX.Element => { | ||
/* eslint-disable react/no-array-index-key */ | ||
return ( | ||
<DataGrid aria-label="User list" data-testid="data-grid" striped> | ||
<DataGridHead> | ||
<DataGridRow> | ||
<DataGridHeader data-testid="header-1">{TableHeaderData[0]}</DataGridHeader> | ||
<DataGridHeader>{TableHeaderData[1]}</DataGridHeader> | ||
<DataGridHeader>{TableHeaderData[2]}</DataGridHeader> | ||
<DataGridHeader>{TableHeaderData[3]}</DataGridHeader> | ||
<DataGridHeader>{TableHeaderData[4]}</DataGridHeader> | ||
<DataGridHeader>Actions</DataGridHeader> | ||
</DataGridRow> | ||
</DataGridHead> | ||
<DataGridBody> | ||
{TableBodyData.map((row, rowIndex) => ( | ||
<DataGridRow key={`row-${rowIndex}`}> | ||
{row.map((col, colIndex) => { | ||
if (colIndex === 0 || colIndex === 1) { | ||
return ( | ||
<InputCell | ||
key={`input-cell-${rowIndex}-${colIndex}`} | ||
colIndex={colIndex} | ||
rowIndex={rowIndex} | ||
value={col} | ||
/> | ||
); | ||
} | ||
if (colIndex === 3) { | ||
return ( | ||
<DataGridCell key={`col-${colIndex}`}> | ||
<EditableCodeBlock | ||
width="300px" | ||
// calculated height based on min row number (20px) * number of rows (6) + padding (2 * 8px) | ||
height="136px" | ||
defaultLanguage="typescript" | ||
defaultValue={`const user: User = new UserAccount("${row[colIndex]}");`} | ||
/> | ||
</DataGridCell> | ||
); | ||
} | ||
if (colIndex === 4) { | ||
return ( | ||
<DataGridCell key={`col-${colIndex}`}> | ||
<Select key={`select-${rowIndex}-${colIndex}`} defaultValue="dogs" aria-label="Phone"> | ||
<Option value="cats">(415) 555-CATS</Option> | ||
<Option value="dogs">(415) 555-DOGS</Option> | ||
<Option value="mice">(415) 555-MICE</Option> | ||
</Select> | ||
</DataGridCell> | ||
); | ||
} | ||
return <DataGridCell key={`col-${colIndex}`}>{col}</DataGridCell>; | ||
})} | ||
<DataGridCell key="col-5"> | ||
<ActionMenu /> | ||
</DataGridCell> | ||
</DataGridRow> | ||
))} | ||
</DataGridBody> | ||
</DataGrid> | ||
); | ||
/* eslint-enable react/no-array-index-key */ | ||
}; |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a patch because no API change for consumers just internal functions