-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mount and nav refactoring, retil-link
- Loading branch information
1 parent
352d9d2
commit f32198d
Showing
77 changed files
with
1,246 additions
and
818 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,15 @@ | ||
const { pathsToModuleNameMapper } = require('ts-jest/utils') | ||
// In the following statement, replace `./tsconfig` with the path to your `tsconfig` file | ||
// which contains the path mapping (ie the `compilerOptions.paths` option): | ||
const { compilerOptions } = require('../../tsconfig') | ||
|
||
module.exports = { | ||
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { | ||
prefix: '<rootDir>/../', | ||
}), | ||
modulePaths: ['<rootDir>/src/'], | ||
modulePathIgnorePatterns: ['<rootDir>/demo/'], | ||
preset: 'ts-jest', | ||
testEnvironment: 'jsdom', | ||
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$', | ||
} |
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,37 @@ | ||
{ | ||
"name": "retil-link", | ||
"version": "0.20.1", | ||
"description": "A composable link component for React apps.", | ||
"author": "James K Nelson <[email protected]>", | ||
"license": "MIT", | ||
"main": "dist/commonjs/index.js", | ||
"module": "dist/es/index.js", | ||
"types": "dist/types/index.d.ts", | ||
"scripts": { | ||
"clean": "rimraf dist", | ||
"build:commonjs": "tsc -p tsconfig.build.json --module commonjs --outDir dist/commonjs", | ||
"build:es": "tsc -p tsconfig.build.json --module es2015 --outDir dist/es", | ||
"build:types": "tsc -p tsconfig.build.json --declaration --emitDeclarationOnly --outDir dist/types --isolatedModules false", | ||
"build": "yarn run clean && yarn build:es && yarn build:commonjs && yarn build:types", | ||
"build:watch": "yarn run clean && yarn build:es -- --types --watch", | ||
"lint": "eslint --ext ts,tsx src", | ||
"prepare": "yarn test && yarn build", | ||
"test": "jest", | ||
"test:watch": "jest --watch" | ||
}, | ||
"dependencies": { | ||
"retil-interaction": "^0.20.1", | ||
"retil-nav": "^0.20.1", | ||
"tslib": "^2.2.0" | ||
}, | ||
"devDependencies": { | ||
"typescript": "4.2.4" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"keywords": [ | ||
"react", | ||
"loader" | ||
] | ||
} |
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 @@ | ||
export * from './link' |
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,81 @@ | ||
import React, { forwardRef } from 'react' | ||
import { | ||
ConnectSurface, | ||
SurfaceProps, | ||
splitSurfaceProps, | ||
} from 'retil-interaction' | ||
import { | ||
NavAction, | ||
UseNavLinkOptions, | ||
useNavLink, | ||
useNavMatch, | ||
useNavResolve, | ||
} from 'retil-nav' | ||
|
||
export interface LinkProps | ||
extends SurfaceProps, | ||
UseNavLinkOptions, | ||
Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'href'> { | ||
active?: boolean | ||
activeClassName?: string | ||
activeStyle?: object | ||
children: React.ReactNode | ||
exact?: boolean | ||
ref?: React.Ref<HTMLAnchorElement> | ||
to: NavAction | ||
} | ||
|
||
// Need to include this type definition, as the automatically generated one | ||
// is incompatible with some versions of the react typings. | ||
export const Link: React.FunctionComponent<LinkProps> = forwardRef( | ||
(props: LinkProps, anchorRef: React.Ref<HTMLAnchorElement>) => { | ||
const [surfaceProps, linkProps] = splitSurfaceProps(props) | ||
|
||
const { | ||
exact, | ||
onClick: onClickProp, | ||
onMouseEnter: onMouseEnterProp, | ||
precacheOn, | ||
replace, | ||
state, | ||
to, | ||
...rest | ||
} = linkProps | ||
|
||
const action = useNavResolve(to, state) | ||
const activeMatch = useNavMatch(action.pathname + (exact ? '' : '*')) | ||
const activated = props.activated ?? activeMatch | ||
|
||
const navLinkProps = useNavLink(action, { | ||
disabled: surfaceProps.disabled, | ||
onClick: onClickProp, | ||
onMouseEnter: onMouseEnterProp, | ||
precacheOn, | ||
replace, | ||
}) | ||
|
||
// Don't handle events on links with a `target` prop. | ||
const onClick = props.target ? onClickProp : navLinkProps.onClick | ||
const onMouseEnter = props.target | ||
? onMouseEnterProp | ||
: navLinkProps.onMouseEnter | ||
|
||
return ( | ||
<ConnectSurface | ||
{...surfaceProps} | ||
activated={activated} | ||
mergeProps={{ | ||
...rest, | ||
...navLinkProps, | ||
ref: anchorRef, | ||
onClick, | ||
onMouseEnter, | ||
}}> | ||
{(props) => ( | ||
// eslint-disable-next-line jsx-a11y/anchor-has-content | ||
<a {...props} /> | ||
)} | ||
</ConnectSurface> | ||
) | ||
}, | ||
) |
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 @@ | ||
{ | ||
"extends": "../../tsconfig.build.json", | ||
"include": [ | ||
"src/**/*" | ||
] | ||
} |
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
6 changes: 3 additions & 3 deletions
6
packages/retil-mount/src/lazyImport.ts → packages/retil-mount/src/loadLazy.ts
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
Oops, something went wrong.