Skip to content

Instantly share code, notes, and snippets.

@eps1lon
Last active August 12, 2021 07:43
Show Gist options
  • Save eps1lon/ab8efe7d4907d3a8d4b6bfb83e63a20b to your computer and use it in GitHub Desktop.
Save eps1lon/ab8efe7d4907d3a8d4b6bfb83e63a20b to your computer and use it in GitHub Desktop.
are material-ui docs converted to ts yet
/* eslint-disable no-console */
/**
* usage:
* `node scripts/areDocsConvertedToTSYet.js > converted.md`
* replace content of the <details /> (keep the <summary />) with
* `converted.md`
*
*/
const fse = require('fs-extra');
const glob = require('glob');
const path = require('path');
const workspaceRoot = path.join(__dirname, '../');
const demosRoot = path.join(workspaceRoot, 'docs/src/pages');
function withExtension(filename, ext) {
const newBasename = path.basename(filename, path.extname(filename)) + ext;
return path.join(path.dirname(filename), newBasename);
}
function hasTSDemo(jsDemoPath) {
return fse.exists(withExtension(jsDemoPath, '.tsx'));
}
async function run() {
const demos = glob
.sync(path.join(demosRoot, '**/*.js'))
.filter(filename => !filename.endsWith('.hooks.js'))
.filter(filename => !filename.includes('getting-started/'))
.filter(filename => !filename.includes('premium-themes/'))
.filter(filename => !filename.includes('versions/'))
.filter(filename => !filename.includes('material-icons/'))
.filter(filename => !filename.includes('customization/color/'))
.filter(filename => !filename.includes('discover-more/'))
.filter(
filename =>
![
'ChipsPlayground.js',
'tileData.js',
'AnchorPlayground.js',
'ScrollPlayground.js',
'DensityTool.js',
'ResponsiveFontSizesChart.js',
'Languages.js',
'Team.js',
'DefaultTheme.js',
].some(othername => filename.endsWith(othername)),
);
const groupedDemos = demos.reduce((acc, demoPath) => {
const group = path.dirname(path.relative(demosRoot, demoPath));
if (!acc.has(group)) {
acc.set(group, []);
}
acc.get(group).push(demoPath);
return acc;
}, new Map());
const groupItems = await Promise.all(
Array.from(groupedDemos).map(async groupEntry => {
const [groupName, demoPaths] = groupEntry;
const listItems = await Promise.all(
demoPaths.map(async demoPath => {
const done = await hasTSDemo(demoPath);
if (done) {
return null;
}
return ` - [ ] ${path.basename(demoPath, path.extname(demoPath))}`;
}),
);
const incompleteListItems = listItems.filter(Boolean);
if (incompleteListItems.length === 0) {
return null;
}
return `- ${groupName}:\n\n${incompleteListItems.join('\n')}\n\n`;
}),
);
const imcompleteGroupItems = groupItems.filter(Boolean);
console.log(imcompleteGroupItems.join('\n'));
}
run().catch(err => {
console.error(err);
process.exit(1);
});

With #13229 we got the proper infrastructure to present our demos both in JavaScript and TypeScript. We want to continue this effort with the goal to have all demos available in TypeScript.

If you want to make contributions to this repository and know a bit of TypeScript we would appreciate you helping us.

Getting started

TL;DR: Use #14739, #14485 or #14535 as example workflows.

  1. Set up your fork (See 'getting started" in the contributing guide).
  2. Choose a demo you want to convert. For this example, we'll use: https://next.material-ui.com/demos/lists/#nested-list
  3. go to ./docs/src/pages/demos/lists/lists.md and find the section. You're looking for a {{ "demo": "some-path" }} block:
  {{"demo": "pages/demos/lists/NestedList.js"}}
                               ^^^ Name of the demo file in `./docs/src/pages/demos/lists/`
  1. Copy this file into the same directory and change the extension to .tsx
  2. Add types
  3. run yarn docs:typescript:check to verify your work
  4. Submit a PR

While working

If you're stuck at any point and the type checker will not let your code pass you can still submit the PR. A maintainer will take a look and provide guidance.

It's important that you don't change any behavior. To verify this you can run yarn docs:typescript:formatted. This will transpile the typescript demos to JavaScript. This should not cause changes in any JavaScript file. It is possible, however, that this will uncover a bug, at which point a change to the JavaScript version is more than welcome. You may encounter some changes in whitespace (mainly added or removed lines). Changes to the JavaScript file are perfectly fine in this case.

Work Items

Missing

  • components/checkboxes:

    • FormControlLabelPosition
  • components/menus:

    • MenuPopupState #17869 17869
  • components/no-ssr:

    • FrameDeferring
    • SimpleNoSsr
  • components/popover:

    • PopoverPopupState
  • components/popper:

    • PopperPopupState
  • components/steppers:

    • SwipeableTextMobileStepper
  • components/tables:

    • MaterialTableDemo
  • components/use-media-query:

    • ServerSide
  • customization/breakpoints:

    • WithWidth
  • customization/components:

    • DynamicCSS
    • DynamicCSSVariables
  • guides/interoperability:

    • StyledComponentsTheme
  • styles/advanced:

    • StringTemplates

done

done
  • components/app-bar:

    • BackToTop
    • BottomAppBar
    • ButtonAppBar
    • DenseAppBar
    • ElevateAppBar #15522
    • HideAppBar #15522
    • MenuAppBar
    • PrimarySearchAppBar
    • SearchAppBar
  • components/autocomplete:

    • IntegrationAutosuggest #15485
    • IntegrationDownshift #15755
    • IntegrationReactSelect #14772
  • components/avatars #14954:

    • IconAvatars
    • ImageAvatars
    • LetterAvatars
  • components/badges:

    • BadgeAlignment
    • BadgeMax #15013
    • BadgeOverlap
    • BadgeVisibility #14969
    • CustomizedBadges
    • DotBadge #14969
    • SimpleBadge #14969
  • components/bottom-navigation #14979:

    • LabelBottomNavigation
    • SimpleBottomNavigation
  • components/breadcrumbs #15139:

    • CollapsedBreadcrumbs
    • CustomizedBreadcrumbs
    • CustomSeparator
    • IconBreadcrumbs
    • RouterBreadcrumbs
    • SimpleBreadcrumbs
  • components/buttons:

    • ButtonBases
    • ButtonSizes
    • ContainedButtons
    • CustomizedButtons
    • FloatingActionButtons
    • FloatingActionButtonZoom
    • GroupedButtons
    • IconButtons
    • IconLabelButtons
    • OutlinedButtons
    • SplitButton #17862
    • TextButtons
  • components/cards:

    • ImgMediaCard #15130
    • MediaCard #15011
    • MediaControlCard #15011
    • RecipeReviewCard #15011
    • SimpleCard #15011
  • components/checkboxes:

    • Checkboxes #15222
    • CheckboxesGroup #15228
    • CheckboxLabels #15237
    • CustomizedCheckbox
  • components/chips:

    • Chips #15052
    • ChipsArray #15050
    • OutlinedChips #15052
    • SmallChips
    • SmallOutlinedChips
  • components/click-away-listener:

    • ClickAway #16322
  • components/container #16322:

    • FixedContainer
    • SimpleContainer
  • components/dialogs:

    • AlertDialog #15271
    • AlertDialogSlide #15271
    • ConfirmationDialog #15273
    • CustomizedDialogs
    • DraggableDialog #15271
    • FormDialog #15271
    • FullScreenDialog #15271
    • MaxWidthDialog #15272
    • ResponsiveDialog #15271
    • ScrollDialog #15271
    • SimpleDialog #15271
  • components/dividers #15037:

    • InsetDividers
    • ListDividers
    • MiddleDividers
    • SubheaderDividers
    • VerticalDividers
  • components/drawers:

    • ClippedDrawer #15284
    • MiniDrawer #15119
    • PermanentDrawerLeft #15119
    • PermanentDrawerRight #15119
    • PersistentDrawerLeft #15119
    • PersistentDrawerRight #15119
    • ResponsiveDrawer #15119
    • SwipeableTemporaryDrawer #15119
    • TemporaryDrawer #15119
  • components/expansion-panels #15162:

    • ControlledExpansionPanels
    • CustomizedExpansionPanels
    • DetailedExpansionPanel
    • SimpleExpansionPanel
  • components/grid-list #15118:

    • AdvancedGridList
    • ImageGridList
    • SingleLineGridList
    • TitlebarGridList
  • components/grid:

    • AutoGrid
    • AutoGridNoWrap
    • CenteredGrid
    • ComplexGrid #15970
    • CSSGrid
    • FullWidthGrid
    • InteractiveGrid
    • NestedGrid
    • SpacingGrid
  • components/hidden:

    • BreakpointDown
    • BreakpointOnly
    • BreakpointUp
    • GridIntegration
  • components/icons:

    • FontAwesome
    • Icons
    • SvgIcons
    • SvgMaterialIcons
  • components/links:

    • ButtonLink #16003
    • Links #16003
  • components/lists:

    • AlignItemsList #15323
    • CheckboxList #15323
    • CheckboxListSecondary #15323
    • FolderList #15323
    • InsetList #15323
    • InteractiveList #15416
    • NestedList #15493
    • PinnedSubheaderList #15323
    • SelectedListItem #15417
    • SimpleList
    • SwitchListSecondary #15493
    • VirtualizedList
  • components/menus:

    • CustomizedMenus
    • FadeMenu
    • LongMenu
    • MenuListComposition
    • SimpleListMenu
    • SimpleMenu
    • TypographyMenu
  • components/modal:

    • ServerModal
    • SimpleModal
    • SpringModal
    • TransitionsModal
  • components/paper:

    • PaperSheet
  • components/pickers #15103:

    • DateAndTimePickers
    • DatePickers
    • MaterialUIPickers
    • TimePickers
  • components/popover #16322:

    • MouseOverPopover
    • SimplePopover
  • components/popper:

    • FakedReferencePopper #16322
    • MinimalPopper #16322
    • NoTransitionPopper #16322
    • PositionedPopper #16322
    • SimplePopper #16004
  • components/portal:

    • SimplePortal
  • components/progress:

    • CircularDeterminate #15104
    • CircularIndeterminate #15104
    • CircularIntegration #15104
    • CircularStatic #15104
    • CircularUnderLoad #15104
    • CustomizedProgressBars
    • DelayingAppearance #15551
    • LinearBuffer #15104
    • LinearDeterminate #15104
    • LinearIndeterminate #15104
    • LinearQuery #15104
  • components/radio-buttons:

    • CustomizedRadios
    • FormControlLabelPosition
    • RadioButtons
    • RadioButtonsGroup
  • components/rating:

    • CustomizedRatings
    • HalfRating
    • HoverRating
    • RatingSize
    • SimpleRating
  • components/selects #15288:

    • ControlledOpenSelect
    • CustomizedSelects
    • DialogSelect
    • MultipleSelect
    • NativeSelects
    • SimpleSelect
  • components/skeleton:

    • Facebook
    • YouTube
  • components/slider:

    • ContinuousSlider
    • CustomizedSlider
    • DiscreteSlider
    • InputSlider
    • RangeSlider
    • TrackFalseSlider
    • TrackInvertedSlider
    • VerticalSlider
  • components/snackbars #15087:

    • ConsecutiveSnackbars
    • CustomizedSnackbars
    • DirectionSnackbar
    • FabIntegrationSnackbar
    • IntegrationNotistack
    • LongTextSnackbar
    • PositionedSnackbar
    • SimpleSnackbar
    • TransitionsSnackbar
  • components/speed-dial:

    • OpenIconSpeedDial
    • SpeedDials
    • SpeedDialTooltipOpen
  • components/steppers:

    • CustomizedSteppers
    • DotsMobileStepper #15223
    • HorizontalLinearAlternativeLabelStepper #15223
    • HorizontalLinearStepper #15223
    • HorizontalNonLinearAlternativeLabelStepper #15223
    • HorizontalNonLinearStepper #15223
    • HorizontalNonLinearStepperWithError #15223
    • ProgressMobileStepper #15223
    • TextMobileStepper #15223
    • VerticalLinearStepper #15223
  • components/switches:

    • CustomizedSwitches
    • FormControlLabelPosition
    • Switches
    • SwitchesGroup
    • SwitchesSize
    • SwitchLabels
  • components/tables:

    • AcccessibleTable
    • CustomizedTables
    • CustomPaginationActionsTable #15086
    • DenseTable #15086
    • EnhancedTable #15755
    • ReactVirtualizedTable #15755
    • SimpleTable #14985
    • SpanningTable #14985
    • StickyHeadTable
  • components/tabs #15053:

    • CenteredTabs
    • CustomizedTabs
    • DisabledTabs
    • FullWidthTabs
    • IconLabelTabs
    • IconTabs
    • NavTabs
    • ScrollableTabsButtonAuto
    • ScrollableTabsButtonForce
    • ScrollableTabsButtonPrevent
    • SimpleTabs
    • TabsWrappedLabel
    • VerticalTabs
  • components/text-fields:

    • ComposedTextField
    • CustomizedInputBase #15209
    • CustomizedInputs
    • FilledInputAdornments
    • FilledTextFields
    • FormattedInputs
    • InputAdornments
    • Inputs
    • InputWithIcon
    • OutlinedInputAdornments
    • OutlinedTextFields
    • TextFieldMargins
    • TextFields
  • components/textarea-autosize:

    • EmptyTextarea
    • MaxHeightTextarea
    • MinHeightTextarea
  • components/toggle-button:

    • CustomizedDividers
  • components/tooltips #15061:

    • ControlledTooltips
    • CustomizedTooltips
    • DelayTooltips
    • DisabledTooltips
    • InteractiveTooltips
    • PositionedTooltips
    • SimpleTooltips
    • TransitionsTooltips
    • TriggersTooltips
    • VariableWidth
  • components/transfer-list:

    • SelectAllTransferList #15419
    • TransferList #15419
  • components/transitions #16003:

    • SimpleCollapse
    • SimpleFade
    • SimpleGrow
    • SimpleSlide
    • SimpleZoom
  • components/tree-view:

    • CustomizedTreeView
    • FileSystemNavigator
    • GmailTreeView
  • components/typography:

    • Types
    • TypographyTheme #16003
  • components/use-media-query:

    • JavaScriptMedia
    • SimpleMediaQuery
    • ThemeHelper
    • UseWidth #17770
  • css-in-js/basics:

    • AdaptingHook
    • AdaptingStyledComponents
  • customization/breakpoints:

    • MediaQuery #17766
  • customization/components:

    • ClassesNesting #16003
    • ClassesShorthand #16003
    • ClassesState #16003
    • ClassNames #17771
    • Component #17790
    • DynamicClassName #17793
    • DynamicInlineStyle #16200
    • DynamicThemeNesting #17788
    • GlobalCssOverride
    • GlobalThemeOverride
    • InlineStyle #17788
    • ThemeVariables
  • customization/globals #17785:

    • DefaultProps
    • GlobalCss
  • customization/palette:

    • DarkTheme
    • Palette #17683
  • customization/theming:

    • CustomStyles
    • ThemeNesting
    • ThemeNestingExtend
  • customization/typography:

    • FontSizeTheme #16334
    • ResponsiveFontSizes
    • TypographyVariants
  • guides/composition:

    • ButtonRouter
    • Composition #16334
    • LinkRouter
    • ListRouter
  • guides/interoperability:

    • EmotionCSS
    • StyledComponents
    • StyledComponentsDeep
    • StyledComponentsPortal
  • guides/right-to-left:

    • Direction #16334
    • RtlOptOut
  • styles/advanced:

    • GlobalClassName #16334
    • GlobalCss #16334
    • HybridGlobalCss #16334
    • ThemeNesting #16334
    • Theming #16334
    • UseTheme #16334
    • WithTheme
  • styles/basics:

    • AdaptingHOC #16134
    • AdaptingHook #16131
    • AdaptingStyledComponents #15548
    • HigherOrderComponent #16334
    • Hook #16334
    • NestedStylesHook
    • StressTest #16334
    • StyledComponents #15548
  • system/basics:

    • CollocationApi
    • CssProp
    • Demo
    • Emotion
    • JSS #15548
    • RealWorld
    • StyledComponents
    • Variant
  • system/borders:

    • BorderAdditive #16875
    • BorderColor #16875
    • BorderRadius #16875
    • BorderSubtractive #16875
  • system/display #16334:

    • Block
    • Hiding
    • Inline
    • Overflow
    • Print
    • TextOverflow
    • Visibility
    • WhiteSpace
  • system/flexbox #16334:

    • AlignContent
    • AlignItems
    • AlignSelf
    • Display
    • FlexDirection
    • FlexGrow
    • FlexShrink
    • FlexWrap
    • JustifyContent
    • Order
  • system/palette #16334:

    • BackgroundColor
    • Color
  • system/positions #16334:

    • ZIndex
  • system/shadows #16334:

    • Demo
  • system/sizing #16334:

    • Height
    • Values
    • Width
  • system/spacing #16334:

    • Demo
    • HorizontalCentering
  • system/typography:

    • FontFamily
    • FontSize
    • FontStyle
    • FontWeight
    • LetterSpacing
    • LineHeight
    • TextAlignment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment