Skip to content

Commit

Permalink
fix linter complain
Browse files Browse the repository at this point in the history
  • Loading branch information
YieldRay committed Apr 3, 2024
1 parent 24d80d9 commit 5f82958
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 44 deletions.
9 changes: 8 additions & 1 deletion src/components/dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ExtendProps } from '@/utils/type'
/**
* @specs https://m3.material.io/components/dialogs/specs
*/
export const Dialog = forwardRef<
const _Dialog = forwardRef<
HTMLDivElement,
ExtendProps<{
headline?: React.ReactNode
Expand Down Expand Up @@ -39,3 +39,10 @@ export const Dialog = forwardRef<
</div>
)
})

const methods = {}

export const Dialog: typeof _Dialog & typeof methods = Object.assign(
_Dialog,
methods,
)
1 change: 1 addition & 0 deletions src/components/list/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const List = forwardRef<
},
ref,
) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const As: any = as || 'div'
return (
<As
Expand Down
7 changes: 5 additions & 2 deletions src/composition/Scrim/Scrim.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@
width: 100%;
height: 100%;

background: rgb(0 0 0 / 0.1);
background: rgb(0 0 0 / 0.3);
transition-property: opacity, display;
transition-duration: 200ms;
transition-behavior: allow-discrete;
overflow: hidden;
overscroll-behavior: contain;

&:not(.sd-scrim-open) {
transition-duration: 250ms;
transition-timing-function: ease-in;
display: none;
opacity: 0;
}
}

.sd-scrim-open {
transition-duration: 200ms;
transition-timing-function: ease-out;
opacity: 1;
@starting-style {
opacity: 0;
Expand Down
3 changes: 0 additions & 3 deletions src/composition/Select/Select.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ const meta: Meta<typeof Select> = {
title: 'composition/Select',
component: Select,
tags: ['autodocs'],
parameters: {
layout: 'centered',
},
args: {
options: fruits.map((fruit) => ({ value: fruit })),
defaultValue: fruits[3],
Expand Down
23 changes: 12 additions & 11 deletions src/composition/SodaTransition/SodaTransition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,21 @@ export const SodaTransition = forwardRef<
if (isIn === false) setShow(false)
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const As: any = as || 'div'

const component = (
<As
{...props}
ref={ref}
style={{ ...style, ...transitionStyle }}
onTransitionEnd={onTransitionEnd}
>
{children}
</As>
return (
show && (
<As
{...props}
ref={ref}
style={{ ...style, ...transitionStyle }}
onTransitionEnd={onTransitionEnd}
>
{children}
</As>
)
)

return show && component
})

/**
Expand Down
42 changes: 15 additions & 27 deletions src/ripple/Ripple.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
import { forwardRef, useEffect, useImperativeHandle, useRef } from 'react'
import { ExtendProps, TagNameString } from '@/utils/type'
import { AsOrChildrenProps, ExtendProps } from '@/utils/type'
import { ripple } from './ripple-effect'

interface RippleProps {
disabled?: boolean
/**
* In ms
*/
rippleDuration?: number
/**
* Any css color string
*/
rippleColor?: string
}

interface RippleRefProps extends RippleProps {
/**
* HTML tag name, div by default
*/
as: TagNameString
children?: React.ReactNode
}

interface RippleFnProps extends RippleProps {
as?: undefined
children: (ref: React.Ref<HTMLElement>) => React.ReactNode
}

type Props = ExtendProps<RippleRefProps | RippleFnProps>
type Props = ExtendProps<
{
disabled?: boolean
/**
* In ms
*/
rippleDuration?: number
/**
* Any css color string
*/
rippleColor?: string
} & AsOrChildrenProps
>

type RippleAt = (
rippleX: number,
Expand Down Expand Up @@ -56,6 +43,7 @@ export const Ripple = forwardRef<RippleHandle, Props>(
})

if (as) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const As = as as any
return (
<As {...props} ref={eRef} disabled={disabled}>
Expand Down
19 changes: 19 additions & 0 deletions src/utils/render.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { createRoot } from 'react-dom/client'

export function renderWithinDiv(
children: React.ReactNode | ((div: HTMLElement) => React.ReactNode),
divAttrs?: Partial<Record<keyof HTMLIFrameElement, string>>,
parentNode: ParentNode = document.body,
) {
const div = document.createElement('div')
if (divAttrs) {
for (const [k, v] of Object.entries(divAttrs)) {
div.setAttribute(k, v)
}
}
parentNode.append(div)
createRoot(div).render(
typeof children === 'function' ? children(div) : children,
)
return div
}
14 changes: 14 additions & 0 deletions src/utils/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,22 @@ export type ExtendProps<

export type TagNameString = keyof JSX.IntrinsicElements

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type As<Props = any> = React.ElementType<Props>

export type PropsOf<T extends As> = React.ComponentPropsWithoutRef<T> & {
as?: As
}

export type AsOrChildrenProps =
| {
as?: undefined
children: (ref: React.Ref<HTMLElement>) => React.ReactNode
}
| {
/**
* HTML tag name, div by default
*/
as: TagNameString
children?: React.ReactNode
}

0 comments on commit 5f82958

Please sign in to comment.