Skip to content

Commit 3d4c3a8

Browse files
Merge pull request #71 from commitd/sh-slider
Typing improvements
2 parents fd678cb + 8a1c008 commit 3d4c3a8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1760
-432
lines changed

.devcontainer/Dockerfile

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@
44
ARG VARIANT="14-buster"
55
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:0-${VARIANT}
66

7-
# [Optional] Uncomment this section to install additional OS packages.
8-
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
9-
# && apt-get -y install --no-install-recommends <your-package-list-here>
10-
11-
# [Optional] Uncomment if you want to install an additional version of node using nvm
12-
# ARG EXTRA_NODE_VERSION=10
13-
# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"
14-
15-
# [Optional] Uncomment if you want to install more global node modules
16-
# RUN sudo -u node npm install -g <your-package-list-here>
7+
# Add additional packages
8+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
9+
# Add utilties
10+
&& sudo apt -y install --no-install-recommends software-properties-common apt-transport-https gnupg2 bash-completion \
11+
# Add key for GitHub CLI
12+
&& sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key C99B11DEB97541F0 \
13+
&& sudo apt-add-repository https://cli.github.com/packages \
14+
&& sudo apt update \
15+
# Install github cli
16+
&& sudo apt -y install --no-install-recommends gh
1717

18+
# Add bash completions
19+
RUN echo 'source <(gh completion -s bash)' >> ~/.bashrc \
20+
&& echo 'source <(kubectl completion bash)' >> ~/.bashrc \
21+
&& echo 'source <(skaffold completion bash)' >> ~/.bashrc \
22+
&& touch ~/.bash_profile

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "4.1.0",
2+
"version": "4.1.1",
33
"name": "@committed/components",
44
"description": "Committed Component Library",
55
"author": "Committed",
@@ -32,7 +32,7 @@
3232
"build-storybook": "build-storybook --docs",
3333
"format": "prettier --write '**/{src,test,stories}/**/{*.js,*.ts,*.tsx,*.json,*.md,*.mdx}' example/index.tsx",
3434
"deploy-storybook": "storybook-to-ghpages",
35-
"danger:local": "danger local --dangerfile dangerfile.lite.ts",
35+
"danger:local": "danger local -b main --dangerfile dangerfile.lite.ts",
3636
"danger:pr": "cross-env DANGER_GITHUB_API_TOKEN=${GITHUB_TOKEN} danger pr https://github.com/commitd/components/pull/${PR}"
3737
},
3838
"peerDependencies": {
@@ -85,16 +85,18 @@
8585
"@storybook/react": "^6.1.11",
8686
"@storybook/storybook-deployer": "^2.8.7",
8787
"@storybook/theming": "^6.1.11",
88+
"@testing-library/dom": "^7.29.0",
8889
"@testing-library/jest-dom": "^5.5.0",
8990
"@testing-library/react": "^10.0.3",
91+
"@testing-library/user-event": "^12.6.0",
9092
"@types/jest": "^25.2.1",
9193
"@types/react": "^16.9.33",
9294
"@types/react-dom": "^16.9.6",
9395
"@typescript-eslint/eslint-plugin": "^4.6.0",
9496
"@typescript-eslint/parser": "^4.6.0",
9597
"babel-jest": "^26.6.1",
9698
"babel-loader": "^8.1.0",
97-
"danger": "^10.1.0",
99+
"danger": "^10.5.4",
98100
"danger-plugin-spellcheck": "^1.5.0",
99101
"eslint-config-prettier": "^6.14.0",
100102
"eslint-config-react-app": "^6.0.0",

src/components/checktoken/CheckToken.tsx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Row } from '../flex/Flex'
77
import { makeStyles, fade } from '../../styles'
88

99
interface CheckboxProps {
10-
color: 'primary' | 'secondary' | 'default'
10+
color?: 'primary' | 'secondary' | 'default'
1111
selected?: boolean | undefined
1212
disabled?: boolean
1313
}
@@ -22,7 +22,7 @@ export interface CheckTokenProps
2222
children?: React.ReactNode
2323
}
2424

25-
export const Checkbox: React.FC<CheckboxProps> = ({
25+
const Checkbox: React.FC<CheckboxProps> = ({
2626
selected,
2727
...props
2828
}: CheckboxProps) => {
@@ -53,7 +53,7 @@ const useStyles = makeStyles((theme) => {
5353
},
5454
selected: {
5555
color: theme.palette.action.active,
56-
borderColor: ({ color }: CheckTokenProps) => {
56+
borderColor: ({ color = 'default' }: CheckTokenProps) => {
5757
if (
5858
color !== 'default' &&
5959
['primary', 'secondary', 'error', 'warning', 'info'].includes(color)
@@ -72,13 +72,24 @@ const useStyles = makeStyles((theme) => {
7272

7373
export const CheckToken = withPositioningProps<CheckTokenProps>(
7474
(props: CheckTokenProps) => {
75-
const { children, onClick, ...rest } = props
75+
const {
76+
children,
77+
onClick,
78+
color = 'default',
79+
value = 'check',
80+
...rest
81+
} = props
7682
const classes = useStyles(props)
7783
return (
78-
<ToggleButton {...rest} onChange={onClick} classes={classes}>
84+
<ToggleButton
85+
{...rest}
86+
onChange={onClick}
87+
value={value}
88+
classes={classes}
89+
>
7990
<Row>
8091
<Checkbox
81-
color={props.color}
92+
color={color}
8293
selected={props.selected}
8394
disabled={props.disabled}
8495
/>
@@ -87,4 +98,4 @@ export const CheckToken = withPositioningProps<CheckTokenProps>(
8798
</ToggleButton>
8899
)
89100
}
90-
)
101+
) as React.ComponentType<CheckTokenProps>

src/components/flex/Flex.tsx

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@ export type ColumnProps = Omit<FlexProps, 'flexDirection'>
77

88
export type FlexRef = HTMLDivElement
99

10-
export const Flex = React.forwardRef<FlexRef, FlexProps>(
11-
(props: FlexProps, ref) => <Box ref={ref} {...props} display="flex" />
12-
)
10+
export const Flex: React.ForwardRefExoticComponent<FlexProps> = React.forwardRef<
11+
FlexRef,
12+
FlexProps
13+
>((props: FlexProps, ref) => <Box ref={ref} {...props} display="flex" />)
1314

14-
export const Row = React.forwardRef<FlexRef, RowProps>(
15-
(props: FlexProps, ref) => (
16-
<Box ref={ref} {...props} display="flex" flexDirection="row" />
17-
)
18-
)
15+
export const Row: React.ForwardRefExoticComponent<RowProps> = React.forwardRef<
16+
FlexRef,
17+
RowProps
18+
>((props: FlexProps, ref) => (
19+
<Box ref={ref} {...props} display="flex" flexDirection="row" />
20+
))
1921

20-
export const Column = React.forwardRef<FlexRef, ColumnProps>(
21-
(props: FlexProps, ref) => (
22-
<Box ref={ref} {...props} display="flex" flexDirection="column" />
23-
)
24-
)
22+
export const Column: React.ForwardRefExoticComponent<ColumnProps> = React.forwardRef<
23+
FlexRef,
24+
ColumnProps
25+
>((props: FlexProps, ref) => (
26+
<Box ref={ref} {...props} display="flex" flexDirection="column" />
27+
))

src/components/grid/Grid.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ export type GridRef = HTMLDivElement
77

88
export const Grid = React.forwardRef<GridRef, GridProps>(
99
(props: GridProps, ref) => <Box ref={ref} {...props} display="grid" />
10-
)
10+
) as React.ForwardRefExoticComponent<GridProps>

src/components/slider/Slider.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ export type SliderProps = BoxProps &
88
onChange?: (e: React.ChangeEvent<{}>, value: number | number[]) => void
99
}
1010

11-
export const Slider = withBoxProps<MaterialSliderProps>(MaterialSlider)
11+
export const Slider = withBoxProps<MaterialSliderProps>(
12+
MaterialSlider
13+
) as React.ComponentType<SliderProps>

src/components/textfield/TextField.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,4 @@ const CommittedTextField: React.FC<CommittedTextFieldProps> = React.forwardRef(
9393

9494
export const TextField = withBoxProps<CommittedTextFieldProps>(
9595
CommittedTextField
96-
)
96+
) as React.ForwardRefExoticComponent<CommittedTextFieldProps>

src/components/typography/Typography.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react'
1+
import React, { ForwardRefExoticComponent } from 'react'
22
import { styled } from '@material-ui/styles'
33
import MaterialTypography, {
44
TypographyProps as MaterialTypographyProps,
@@ -12,8 +12,13 @@ type BaseTypographyProps<C extends React.ElementType> = MaterialTypographyProps<
1212
> &
1313
PositioningProps
1414

15+
// function test() {
16+
// const ref = React.useRef(null)
17+
// return <MaterialTypography ref={ref} />
18+
// }
19+
1520
const BaseTypography = withPositioningProps<MaterialTypographyProps>(
16-
MaterialTypography
21+
MaterialTypography as ForwardRefExoticComponent<MaterialTypographyProps>
1722
)
1823

1924
export type ExtraTypographyProps = {

src/internal/noopener.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function withNoOpener<P extends AProps & { ref?: React.Ref<any> }>(
1414
Component: React.ForwardRefExoticComponent<P>
1515
): React.ForwardRefExoticComponent<P>
1616

17-
export function withNoOpener<P>(
17+
export function withNoOpener<P extends AProps>(
1818
Component: React.FunctionComponent<P>
1919
): React.ForwardRefExoticComponent<P>
2020

src/internal/wrappers.tsx

Lines changed: 64 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,26 @@ import { omit } from '../util/transform'
1616

1717
export type { SizingProps }
1818

19-
export type BoxProps = SpacingProps &
20-
FlexboxProps &
21-
SizingProps &
22-
DisplayProps &
23-
GriditemProps
24-
2519
export type PositioningProps = SpacingProps &
2620
FlexboxProps &
2721
DisplayProps &
2822
GriditemProps
2923

30-
// The natural typing causes typescript to error, hence the casts to force it.
31-
export const withPositioning = <P extends object>(
32-
WrappedComponent: React.ElementType<P>
33-
) =>
34-
(styled(WrappedComponent)(
35-
compose(display, spacing, flexbox, griditem)
36-
) as unknown) as React.ComponentType<P & PositioningProps>
24+
export type BoxProps = PositioningProps & SizingProps
3725

38-
export const boxPropsKeys: Array<keyof BoxProps> = [
26+
export const sizingPropsKeys: Array<keyof SizingProps> = [
27+
'width',
28+
'maxWidth',
29+
'minWidth',
30+
'height',
31+
'maxHeight',
32+
'minHeight',
33+
'sizeWidth',
34+
'sizeHeight',
35+
'boxSizing',
36+
]
37+
38+
export const positioningPropsKeys: Array<keyof PositioningProps> = [
3939
'm',
4040
'mt',
4141
'mr',
@@ -77,14 +77,6 @@ export const boxPropsKeys: Array<keyof BoxProps> = [
7777
'alignSelf',
7878
'justifyItems',
7979
'justifySelf',
80-
'width',
81-
'maxWidth',
82-
'minWidth',
83-
'height',
84-
'maxHeight',
85-
'minHeight',
86-
'sizeWidth',
87-
'sizeHeight',
8880
'display',
8981
'displayPrint',
9082
'overflow',
@@ -101,30 +93,62 @@ export const boxPropsKeys: Array<keyof BoxProps> = [
10193
'placeSelf',
10294
]
10395

104-
export const withBoxProps = <P extends object>(
96+
export const boxPropsKeys: Array<keyof BoxProps> = [
97+
...positioningPropsKeys,
98+
...sizingPropsKeys,
99+
]
100+
101+
type WrapperType<T> = {
102+
<P extends object & { ref?: React.Ref<any> }>(
103+
Component: React.ForwardRefExoticComponent<P>
104+
): React.ForwardRefExoticComponent<P & T>
105+
<P extends object>(
106+
Component: React.FunctionComponent<P>
107+
): React.ForwardRefExoticComponent<P & T>
108+
<P extends object>(
109+
WrappedComponent: React.ComponentType<P>
110+
): React.ComponentType<P & T>
111+
}
112+
113+
export const withBoxProps: WrapperType<BoxProps> = <P extends object>(
105114
WrappedComponent: React.ComponentType<P>
106115
) =>
107-
styled((props) => {
108-
const rest = omit(props, boxPropsKeys) as any
109-
return <WrappedComponent {...rest} />
110-
})(
116+
styled(
117+
React.forwardRef<React.ComponentType<P>, P & BoxProps>(function withBox(
118+
props,
119+
ref
120+
) {
121+
const rest = omit(props, boxPropsKeys) as any
122+
return <WrappedComponent {...rest} ref={ref} />
123+
})
124+
)(
111125
compose(display, spacing, flexbox, sizing, griditem)
112-
) as React.ComponentType<P & BoxProps>
126+
) as React.ForwardRefExoticComponent<P & BoxProps>
113127

114-
export const withPositioningProps = <P extends object>(
128+
export const withPositioningProps: WrapperType<PositioningProps> = <
129+
P extends object
130+
>(
115131
WrappedComponent: React.ComponentType<P>
116132
) =>
117-
styled((props) => {
118-
const rest = omit(props, boxPropsKeys) as any
119-
return <WrappedComponent {...rest} />
120-
})(compose(display, spacing, flexbox, griditem)) as React.ComponentType<
121-
P & PositioningProps
122-
>
133+
styled(
134+
React.forwardRef<React.ComponentType<P>, P & PositioningProps>(
135+
function withPositioning(props, ref) {
136+
const rest = omit(props, positioningPropsKeys) as any
137+
return <WrappedComponent {...rest} ref={ref} />
138+
}
139+
)
140+
)(
141+
compose(display, spacing, flexbox, griditem)
142+
) as React.ForwardRefExoticComponent<P & PositioningProps>
123143

124-
export const withSizingProps = <P extends object>(
144+
export const withSizingProps: WrapperType<SizingProps> = <P extends object>(
125145
WrappedComponent: React.ComponentType<P>
126146
) =>
127-
styled((props) => {
128-
const rest = omit(props, boxPropsKeys) as any
129-
return <WrappedComponent {...rest} />
130-
})(sizing) as React.ComponentType<P & SizingProps>
147+
styled(
148+
React.forwardRef<React.ComponentType<P>, P & SizingProps>(
149+
function withSizing(props, ref) {
150+
const rest = omit(props, sizingPropsKeys) as any
151+
return <WrappedComponent {...rest} ref={ref} />
152+
}
153+
)
154+
)(sizing) as React.ForwardRefExoticComponent<P & SizingProps>

0 commit comments

Comments
 (0)