Skip to content

Instantly share code, notes, and snippets.

View kgregory's full-sized avatar
Yes, have some.

Ken Gregory kgregory

Yes, have some.
View GitHub Profile
@kgregory
kgregory / Stack.tsx
Last active January 18, 2022 03:40
Stack component, vertically flex components
import * as React from "react";
import { makeStyles } from "@material-ui/core/styles";
interface StackProps
extends React.DetailedHTMLProps<
React.HTMLAttributes<HTMLDivElement>,
HTMLDivElement
> {
gap?: number;
reverse?: boolean;
@kgregory
kgregory / Inline.tsx
Last active January 18, 2022 03:39
Inline component, horizontally flex components
import * as React from "react";
import { makeStyles } from "@material-ui/core/styles";
interface InlineProps
extends React.DetailedHTMLProps<
React.HTMLAttributes<HTMLDivElement>,
HTMLDivElement
> {
gap?: number;
reverse?: boolean;
@kgregory
kgregory / StickyListSubheader.jsx
Last active August 12, 2021 16:30
Sticky Material-UI ListSubheader that appears beneath fixed AppBar
import ListSubheader from "@material-ui/core/ListSubheader";
import { makeStyles } from "@material-ui/core/styles";
/**
* I have a separate gist for this that explains it a bit
* we do this because the app bar's height is dynamic based on the viewport size
* see: https://gist.github.com/e15657481aea15c440867de710399ea9
*/
const toolbarRelativeStyles = (property, theme, modifier = (value) => value) =>
Object.keys(theme.mixins.toolbar).reduce((style, key) => {
@kgregory
kgregory / useMenu.ts
Last active July 2, 2021 12:55
Hook to establish the relationship between a button and its popup menu
/**
* A hook that helps establish the relationship between button and menu
* Intended for Material-UI IconButton and Menu components, but would work nicely elsewhere
*/
import type { MouseEventHandler } from "react";
import { useMemo, useState } from "react";
interface UseMenuResults {
ButtonProps: {
"aria-controls"?: string,
@kgregory
kgregory / MuiVirtualizedTable.jsx
Created November 21, 2018 16:36
Virtualized, Auto-Height Table powered by material-ui and react-virtualized
import React from "react";
import { PropTypes } from "prop-types";
import classNames from "classnames";
import withStyles from "@material-ui/core/styles/withStyles";
import TableCell from "@material-ui/core/TableCell";
import TableSortLabel from "@material-ui/core/TableSortLabel";
import {
AutoSizer,
Column,
SortDirection,
@kgregory
kgregory / toolbarRelativeStyles.js
Last active May 11, 2021 14:53
Build JSS with property relative to material-ui theme Toolbar height
/*
Since the release of material-ui 1.0.0-beta.11, there is a toolbar mixin available
on the theme that provides the toolbar minHeight for each breakpoint. If you need to style
an element relative to the standard height of the AppBar component, you can use this
object to build your own styles.
In this gist, toolbarRelativeProperties returns an object that can be spread into your
style object. It addresses the simple case of setting a specified attribute to a value
that is based on the AppBar height.