Skip to content

Commit

Permalink
reintroduce npm packages
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-burel committed Sep 23, 2020
1 parent 99631fa commit 8de7e88
Show file tree
Hide file tree
Showing 48 changed files with 712 additions and 10 deletions.
88 changes: 88 additions & 0 deletions packages/@vulcan/next-material-ui/components/Link.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// @see https://github.com/mui-org/material-ui/blob/master/examples/nextjs/src/Link.js
// /* eslint-disable jsx-a11y/anchor-has-content */
import React, { Ref } from "react";
import PropTypes from "prop-types";
import clsx from "clsx";
import { useRouter } from "next/router";
import NextLink, { LinkProps as NextLinkProps } from "next/link";
import MuiLink, { LinkProps as MuiLinkProps } from "@material-ui/core/Link";

type LinkProps = NextLinkProps &
MuiLinkProps & {
activeClassName?: string;
naked?: boolean;
};

const NextComposed = React.forwardRef(function NextComposed(
props: LinkProps,
ref: Ref<HTMLAnchorElement>
) {
const { as, href, ...other } = props;

return (
<NextLink href={href} as={as}>
<a ref={ref} {...other} />
</NextLink>
);
});

NextComposed.propTypes = {
as: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
// href: PropTypes.oneOfType([PropTypes.string, PropTypes.object]), // FIXME: provokes a TS error
prefetch: PropTypes.bool,
};

// A styled version of the Next.js Link component:
// https://nextjs.org/docs/#with-link
function Link(props: LinkProps) {
const {
href,
activeClassName = "active",
className: classNameProps,
innerRef,
naked,
...other
} = props;

const router = useRouter();
const pathname = typeof href === "string" ? href : href.pathname;
const className = clsx(classNameProps, {
[activeClassName]: router.pathname === pathname && activeClassName,
});

if (naked) {
return (
<NextComposed
className={className}
ref={innerRef}
href={href}
{...other}
/>
);
}

return (
<MuiLink
component={NextComposed}
className={className}
ref={innerRef}
href={href}
{...other}
/>
);
}

Link.propTypes = {
activeClassName: PropTypes.string,
as: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
className: PropTypes.string,
href: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
innerRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
naked: PropTypes.bool,
onClick: PropTypes.func,
prefetch: PropTypes.bool,
};

export default React.forwardRef((props: LinkProps, ref) => (
<Link {...props} innerRef={ref} />
));
9 changes: 9 additions & 0 deletions packages/@vulcan/next-material-ui/dist/components/Link.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from "react";
import { LinkProps as NextLinkProps } from "next/link";
import { LinkProps as MuiLinkProps } from "@material-ui/core/Link";
declare type LinkProps = NextLinkProps & MuiLinkProps & {
activeClassName?: string;
naked?: boolean;
};
declare const _default: React.ForwardRefExoticComponent<Pick<LinkProps, "dir" | "slot" | "style" | "title" | "className" | "classes" | "innerRef" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "noWrap" | "gutterBottom" | "paragraph" | "align" | "display" | "variant" | "variantMapping" | "download" | "href" | "hrefLang" | "media" | "ping" | "rel" | "target" | "type" | "referrerPolicy" | "as" | "replace" | "scroll" | "shallow" | "passHref" | "prefetch" | "TypographyClasses" | "underline" | "activeClassName" | "naked"> & React.RefAttributes<unknown>>;
export default _default;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { AppSheetsCollector } from "@vulcan/next-style-collector";
export declare const getAppEnhancer: () => AppSheetsCollector;
3 changes: 3 additions & 0 deletions packages/@vulcan/next-material-ui/dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { default as useMuiApp } from "./useMuiApp";
export * from "./getMuiDocumentInitialProps";
export { default as Link } from "./components/Link";
2 changes: 2 additions & 0 deletions packages/@vulcan/next-material-ui/dist/index.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from "react";
import { LinkProps as NextLinkProps } from "next/link";
import { LinkProps as MuiLinkProps } from "@material-ui/core/Link";
declare type LinkProps = NextLinkProps & MuiLinkProps & {
activeClassName?: string;
naked?: boolean;
};
declare const _default: React.ForwardRefExoticComponent<Pick<LinkProps, "dir" | "slot" | "style" | "title" | "className" | "classes" | "innerRef" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "noWrap" | "gutterBottom" | "paragraph" | "align" | "display" | "variant" | "variantMapping" | "download" | "href" | "hrefLang" | "media" | "ping" | "rel" | "target" | "type" | "referrerPolicy" | "as" | "replace" | "scroll" | "shallow" | "passHref" | "prefetch" | "TypographyClasses" | "underline" | "activeClassName" | "naked"> & React.RefAttributes<unknown>>;
export default _default;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { AppSheetsCollector } from "@vulcan/next-style-collector";
export declare const getAppEnhancer: () => AppSheetsCollector;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { default as useMuiApp } from "./useMuiApp";
export * from "./getMuiDocumentInitialProps";
export { default as Link } from "./components/Link";
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const useMuiApp: () => void;
export default useMuiApp;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface AppSheetsCollector {
sheets: {
getStyleElement: Function;
};
enhanceApp: Function;
finally?: Function;
}
2 changes: 2 additions & 0 deletions packages/@vulcan/next-material-ui/dist/useMuiApp.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const useMuiApp: () => void;
export default useMuiApp;
63 changes: 63 additions & 0 deletions packages/@vulcan/next-material-ui/getMuiDocumentInitialProps.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React from "react";
import { ServerStyleSheets } from "@material-ui/core/styles";
import { AppSheetsCollector } from "@vulcan/next-style-collector";

export const getAppEnhancer = (): AppSheetsCollector => {
const sheets = new ServerStyleSheets();
const enhanceApp = (App) => (props) => sheets.collect(<App {...props} />);
return {
sheets,
enhanceApp,
};
};

// @see https://github.com/mui-org/material-ui/blob/master/examples/nextjs/pages/_document.js
// This function do not generalize when you have another lib collecting stylesheets (eg Styled Components)
/*
const getMuiDocumentInitialProps = async (ctx: DocumentContext) => {
// Resolution order
//
// On the server:
// 1. app.getInitialProps
// 2. page.getInitialProps
// 3. document.getInitialProps
// 4. app.render
// 5. page.render
// 6. document.render
//
// On the server with error:
// 1. document.getInitialProps
// 2. app.render
// 3. page.render
// 4. document.render
//
// On the client
// 1. app.getInitialProps
// 2. page.getInitialProps
// 3. app.render
// 4. page.render
// Render app and page and get the context of the page with collected side effects.
const sheets = new ServerStyleSheets();
const originalRenderPage = ctx.renderPage;
ctx.renderPage = () =>
originalRenderPage({
enhanceApp: (App) => (props) => sheets.collect(<App {...props} />),
});
// get parent props
// NOTE: we need to have already enhanced ctx, so it has to be done here
const initialProps = await Document.getInitialProps(ctx);
return {
// Styles fragment is rendered after the app and page rendering finish.
...initialProps,
styles: [
...React.Children.toArray(initialProps.styles),
sheets.getStyleElement(),
],
};
};
export default getMuiDocumentInitialProps;
*/
5 changes: 5 additions & 0 deletions packages/@vulcan/next-material-ui/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export { default as useMuiApp } from "./useMuiApp";

export * from "./getMuiDocumentInitialProps";

export { default as Link } from "./components/Link";
26 changes: 26 additions & 0 deletions packages/@vulcan/next-material-ui/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@vulcan/next-material-ui",
"version": "0.0.1",
"description": "Vulcan Next Material UI binding",
"main": "./dist/index.js",
"author": "eric-burel <[email protected]>",
"homepage": "https://github.com/VulcanJS/vulcan-npm#readme",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/VulcanJS/vulcan-npm.git"
},
"scripts": {
"test": "echo \"Error: run tests from root\" && exit 1",
"build": "webpack --config ./webpack.config.js"
},
"bugs": {
"url": "https://github.com/VulcanJS/vulcan-npm/issues"
},
"dependencies": {
"@material-ui/core": "^4.11.0",
"clsx": "^1.1.1",
"next": "^9.5.3",
"react-dom": "^16.13.1"
}
}
8 changes: 8 additions & 0 deletions packages/@vulcan/next-material-ui/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist",
"lib": ["es6", "dom"]
},
"include": ["*.ts"]
}
13 changes: 13 additions & 0 deletions packages/@vulcan/next-material-ui/useMuiApp.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// @see https://github.com/mui-org/material-ui/blob/master/examples/nextjs/pages/_app.js
import { useEffect } from "react";

const useMuiApp = () => {
useEffect(() => {
// Remove the server-side injected CSS on each render
const jssStyles = document.querySelector("#jss-server-side");
if (jssStyles) {
jssStyles.parentElement.removeChild(jssStyles);
}
}, []);
};
export default useMuiApp;
12 changes: 12 additions & 0 deletions packages/@vulcan/next-material-ui/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const merge = require("webpack-merge");
const path = require("path");
const baseConfig = require("../../webpack/webpack.config.base.common.prod");
// @see https://stackoverflow.com/questions/46010926/how-to-use-webpack-with-a-monorepo-yarnpkg-workspaces

//const merge = require('webpack-merge')
module.exports = merge(baseConfig, {
entry: path.resolve(__dirname, "./index.ts"),
output: {
path: path.resolve(__dirname, "dist"),
},
});
7 changes: 7 additions & 0 deletions packages/@vulcan/next-style-collector/dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface AppSheetsCollector {
sheets: {
getStyleElement: Function;
};
enhanceApp: Function;
finally?: Function;
}
Loading

0 comments on commit 8de7e88

Please sign in to comment.