-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
432 additions
and
3 deletions.
There are no files selected for viewing
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,102 @@ | ||
const fs = require('fs'); | ||
|
||
const pluginName = 'babel-plugin-jsx-preview'; | ||
|
||
/** | ||
* @returns {import('@babel/core').PluginObj} | ||
*/ | ||
export default function babelPluginJsxPreview() { | ||
const wrapperTypes = ['div', 'Box', 'Stack']; | ||
|
||
/** | ||
* @type {import('@babel/core').types.JSXElement | import('@babel/core').types.JSXElement['children']} | ||
*/ | ||
let previewNode = null; | ||
|
||
return { | ||
name: pluginName, | ||
visitor: { | ||
ExportDefaultDeclaration(path) { | ||
const { declaration } = path.node; | ||
if (declaration.type !== 'FunctionDeclaration') { | ||
return; | ||
} | ||
const { body } = declaration.body; | ||
/** | ||
* @type {import('@babel/core').types.ReturnStatement[]} | ||
*/ | ||
const [lastReturn] = body | ||
.filter((statement) => { | ||
return statement.type === 'ReturnStatement'; | ||
}) | ||
.reverse(); | ||
|
||
const returnedJSX = lastReturn.argument; | ||
if (returnedJSX.type === 'JSXElement') { | ||
previewNode = returnedJSX; | ||
if ( | ||
wrapperTypes.includes(previewNode.openingElement.name.name) && | ||
previewNode.children.length > 0 | ||
) { | ||
// Trim blank JSXText to normalize | ||
// return ( | ||
// <div /> | ||
// ) | ||
// and | ||
// return ( | ||
// <Stack> | ||
// <div /> | ||
// ^^^^ Blank JSXText including newline | ||
// </Stacke> | ||
// ) | ||
previewNode = previewNode.children.filter((child, index, children) => { | ||
const isSurroundingBlankJSXText = | ||
(index === 0 || index === children.length - 1) && | ||
child.type === 'JSXText' && | ||
!/[^\s]+/.test(child.value); | ||
return !isSurroundingBlankJSXText; | ||
}); | ||
} | ||
} | ||
}, | ||
}, | ||
post(state) { | ||
const { maxLines, outputFilename } = state.opts.plugins.find((plugin) => { | ||
return plugin.key === pluginName; | ||
}).options; | ||
|
||
let hasPreview = false; | ||
if (previewNode !== null) { | ||
const [startNode, endNode] = Array.isArray(previewNode) | ||
? [previewNode[0], previewNode.slice(-1)[0]] | ||
: [previewNode, previewNode]; | ||
const preview = state.code.slice(startNode.start, endNode.end); | ||
|
||
const previewLines = preview.split(/\n/); | ||
// The first line is already trimmed either due to trimmed blank JSXText or because it's a single node which babel already trims. | ||
// The last line is therefore the meassure for indendation | ||
const indendation = previewLines.slice(-1)[0].match(/^\s*/)[0].length; | ||
const deindentedPreviewLines = preview.split(/\n/).map((line, index) => { | ||
if (index === 0) { | ||
return line; | ||
} | ||
return line.slice(indendation); | ||
}); | ||
|
||
if (deindentedPreviewLines.length <= maxLines) { | ||
fs.writeFileSync(outputFilename, deindentedPreviewLines.join('\n')); | ||
hasPreview = true; | ||
} | ||
} | ||
|
||
if (!hasPreview) { | ||
try { | ||
fs.unlinkSync(outputFilename); | ||
} catch (error) { | ||
// Would throw if the file doesn't exist. | ||
// But we do want to ensure that the file doesn't exist so the error is fine. | ||
} | ||
} | ||
}, | ||
}; | ||
} |
10 changes: 10 additions & 0 deletions
10
docs/src/pages/components/data-grid/columns/BasicColumnsGrid.tsx.preview
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,10 @@ | ||
<DataGrid | ||
columns={[{ field: 'username' }, { field: 'age' }]} | ||
rows={[ | ||
{ | ||
id: 1, | ||
username: '@MUI', | ||
age: 20, | ||
}, | ||
]} | ||
/> |
4 changes: 4 additions & 0 deletions
4
docs/src/pages/components/data-grid/columns/ColumnMinWidthGrid.tsx.preview
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,4 @@ | ||
<DataGrid | ||
columns={[{ field: 'username', minWidth: 150 }, { field: 'age' }]} | ||
rows={rows} | ||
/> |
8 changes: 8 additions & 0 deletions
8
docs/src/pages/components/data-grid/columns/ColumnOrderingDisabledGrid.tsx.preview
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,8 @@ | ||
<DataGridPro | ||
columns={[ | ||
{ field: 'id' }, | ||
{ field: 'username' }, | ||
{ field: 'age', disableReorder: true }, | ||
]} | ||
rows={rows} | ||
/> |
8 changes: 8 additions & 0 deletions
8
docs/src/pages/components/data-grid/columns/ColumnSizingGrid.tsx.preview
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,8 @@ | ||
<DataGridPro | ||
columns={[ | ||
{ field: 'id' }, | ||
{ field: 'username', minWidth: 150 }, | ||
{ field: 'age', resizable: false }, | ||
]} | ||
rows={rows} | ||
/> |
1 change: 1 addition & 0 deletions
1
docs/src/pages/components/data-grid/columns/ColumnTypesGrid.tsx.preview
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 @@ | ||
<DataGrid columns={columns} rows={rows} /> |
4 changes: 4 additions & 0 deletions
4
docs/src/pages/components/data-grid/columns/ColumnWidthGrid.tsx.preview
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,4 @@ | ||
<DataGrid | ||
columns={[{ field: 'username', width: 200 }, { field: 'age' }]} | ||
rows={rows} | ||
/> |
8 changes: 8 additions & 0 deletions
8
docs/src/pages/components/data-grid/columns/CustomColumnTypesGrid.tsx.preview
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,8 @@ | ||
<DataGrid | ||
columns={[ | ||
{ field: 'status', width: 130 }, | ||
{ field: 'subTotal', ...usdPrice }, | ||
{ field: 'total', ...usdPrice }, | ||
]} | ||
rows={rows} | ||
/> |
12 changes: 12 additions & 0 deletions
12
docs/src/pages/components/data-grid/columns/HeaderColumnsGrid.tsx.preview
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,12 @@ | ||
<DataGrid | ||
columns={[ | ||
{ | ||
field: 'username', | ||
headerName: 'Username', | ||
description: | ||
'The identification used by the person with access to the online service.', | ||
}, | ||
{ field: 'age', headerName: 'Age' }, | ||
]} | ||
rows={rows} | ||
/> |
1 change: 1 addition & 0 deletions
1
docs/src/pages/components/data-grid/columns/RenderCellGrid.tsx.preview
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 @@ | ||
<DataGrid rows={rows} columns={columns} /> |
1 change: 1 addition & 0 deletions
1
docs/src/pages/components/data-grid/columns/RenderExpandCellGrid.tsx.preview
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 @@ | ||
<DataGrid rows={rows} columns={columns} /> |
1 change: 1 addition & 0 deletions
1
docs/src/pages/components/data-grid/columns/ValueGetterGrid.tsx.preview
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 @@ | ||
<DataGrid rows={rows} columns={columns} /> |
7 changes: 7 additions & 0 deletions
7
docs/src/pages/components/data-grid/components/CustomEmptyOverlayGrid.tsx.preview
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,7 @@ | ||
<DataGrid | ||
components={{ | ||
NoRowsOverlay: CustomNoRowsOverlay, | ||
}} | ||
rows={[]} | ||
columns={data.columns} | ||
/> |
7 changes: 7 additions & 0 deletions
7
docs/src/pages/components/data-grid/components/CustomLoadingOverlayGrid.tsx.preview
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,7 @@ | ||
<DataGrid | ||
components={{ | ||
LoadingOverlay: CustomLoadingOverlay, | ||
}} | ||
loading | ||
{...data} | ||
/> |
9 changes: 9 additions & 0 deletions
9
docs/src/pages/components/data-grid/components/CustomPaginationGrid.tsx.preview
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,9 @@ | ||
<DataGrid | ||
pagination | ||
pageSize={5} | ||
rowsPerPageOptions={[5]} | ||
components={{ | ||
Pagination: CustomPagination, | ||
}} | ||
{...data} | ||
/> |
12 changes: 12 additions & 0 deletions
12
docs/src/pages/components/data-grid/components/CustomSortIcons.tsx.preview
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,12 @@ | ||
<DataGrid | ||
columns={columns} | ||
rows={rows} | ||
sortModel={[ | ||
{ field: 'name', sort: 'asc' }, | ||
{ field: 'stars', sort: 'desc' }, | ||
]} | ||
components={{ | ||
ColumnSortedDescendingIcon: SortedDescendingIcon, | ||
ColumnSortedAscendingIcon: SortedAscendingIcon, | ||
}} | ||
/> |
1 change: 1 addition & 0 deletions
1
docs/src/pages/components/data-grid/editing/BasicEditingGrid.tsx.preview
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 @@ | ||
<DataGrid rows={rows} columns={columns} /> |
1 change: 1 addition & 0 deletions
1
docs/src/pages/components/data-grid/editing/BasicRowEditingGrid.tsx.preview
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 @@ | ||
<DataGrid editMode="row" rows={rows} columns={columns} /> |
8 changes: 8 additions & 0 deletions
8
docs/src/pages/components/data-grid/editing/CatchEditingEventsGrid.tsx.preview
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,8 @@ | ||
<div style={{ height: 180, width: '100%' }}> | ||
<DataGridPro rows={rows} columns={columns} apiRef={apiRef} /> | ||
</div> | ||
{message && ( | ||
<Alert severity="info" style={{ marginTop: 8 }}> | ||
{message} | ||
</Alert> | ||
)} |
11 changes: 11 additions & 0 deletions
11
docs/src/pages/components/data-grid/editing/CellEditControlGrid.tsx.preview
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,11 @@ | ||
<Alert severity="info" style={{ marginBottom: 8 }}> | ||
<code>editRowsModel: {JSON.stringify(editRowsModel)}</code> | ||
</Alert> | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGrid | ||
rows={rows} | ||
columns={columns} | ||
editRowsModel={editRowsModel} | ||
onEditRowsModelChange={handleEditRowsModelChange} | ||
/> | ||
</div> |
8 changes: 8 additions & 0 deletions
8
docs/src/pages/components/data-grid/editing/ConditionalValidationGrid.tsx.preview
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,8 @@ | ||
<DataGrid | ||
className={classes.root} | ||
rows={rows} | ||
columns={columns} | ||
editMode="row" | ||
editRowsModel={editRowsModel} | ||
onEditRowsModelChange={handleEditRowsModelChange} | ||
/> |
15 changes: 15 additions & 0 deletions
15
docs/src/pages/components/data-grid/editing/FullFeaturedCrudGrid.tsx.preview
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,15 @@ | ||
<DataGridPro | ||
rows={rows} | ||
columns={columns} | ||
apiRef={apiRef} | ||
editMode="row" | ||
onRowEditStart={handleRowEditStart} | ||
onRowEditStop={handleRowEditStop} | ||
onCellFocusOut={handleCellFocusOut} | ||
components={{ | ||
Toolbar: EditToolbar, | ||
}} | ||
componentsProps={{ | ||
toolbar: { apiRef }, | ||
}} | ||
/> |
6 changes: 6 additions & 0 deletions
6
docs/src/pages/components/data-grid/editing/IsCellEditableGrid.tsx.preview
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,6 @@ | ||
<DataGrid | ||
className={classes.root} | ||
rows={rows} | ||
columns={columns} | ||
isCellEditable={(params) => params.row.age % 2 === 0} | ||
/> |
1 change: 1 addition & 0 deletions
1
docs/src/pages/components/data-grid/editing/RenderRatingEditCellGrid.tsx.preview
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 @@ | ||
<DataGrid rows={rows} columns={columns} /> |
12 changes: 12 additions & 0 deletions
12
docs/src/pages/components/data-grid/editing/RowEditControlGrid.tsx.preview
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,12 @@ | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGrid | ||
rows={rows} | ||
columns={columns} | ||
editRowsModel={editRowsModel} | ||
editMode="row" | ||
onEditRowsModelChange={handleEditRowsModelChange} | ||
/> | ||
</div> | ||
<Alert severity="info" style={{ marginTop: 8 }}> | ||
<code>editRowsModel: {JSON.stringify(editRowsModel)}</code> | ||
</Alert> |
7 changes: 7 additions & 0 deletions
7
docs/src/pages/components/data-grid/editing/ValidateRowModelControlGrid.tsx.preview
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,7 @@ | ||
<DataGrid | ||
className={classes.root} | ||
rows={rows} | ||
columns={columns} | ||
editRowsModel={editRowsModel} | ||
onEditRowsModelChange={handleEditRowsModelChange} | ||
/> |
8 changes: 8 additions & 0 deletions
8
docs/src/pages/components/data-grid/editing/ValidateServerNameGrid.tsx.preview
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,8 @@ | ||
<DataGridPro | ||
className={classes.root} | ||
apiRef={apiRef} | ||
rows={rows} | ||
columns={columns} | ||
onEditCellPropsChange={handleCellEditPropsChange} | ||
isCellEditable={(params) => params.row.id === 5} | ||
/> |
1 change: 1 addition & 0 deletions
1
docs/src/pages/components/data-grid/editing/ValueGetterSetterGrid.tsx.preview
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 @@ | ||
<DataGrid rows={defaultRows} columns={columns} /> |
8 changes: 8 additions & 0 deletions
8
docs/src/pages/components/data-grid/events/SubscribeToEvents.tsx.preview
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,8 @@ | ||
<div style={{ height: 180, width: '100%' }}> | ||
<DataGridPro apiRef={apiRef} {...data} /> | ||
</div> | ||
{message && ( | ||
<Alert severity="info" style={{ marginTop: 8 }}> | ||
{message} | ||
</Alert> | ||
)} |
14 changes: 14 additions & 0 deletions
14
docs/src/pages/components/data-grid/filtering/ColumnTypeFilteringGrid.tsx.preview
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,14 @@ | ||
<DataGrid | ||
rows={data.rows} | ||
columns={columns} | ||
columnTypes={{ price: priceColumnType }} | ||
initialState={{ | ||
filter: { | ||
filterModel: { | ||
items: [ | ||
{ columnField: 'totalPrice', value: '3000000', operatorValue: '>' }, | ||
], | ||
}, | ||
}, | ||
}} | ||
/> |
6 changes: 6 additions & 0 deletions
6
docs/src/pages/components/data-grid/filtering/CustomRatingOperator.tsx.preview
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,6 @@ | ||
<DataGrid | ||
rows={data.rows} | ||
columns={columns} | ||
filterModel={filterModel} | ||
onFilterModelChange={(model) => setFilterModel(model)} | ||
/> |
Oops, something went wrong.