Skip to content

Commit

Permalink
Merge pull request #463 from illa-family/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Z-AOAO authored May 19, 2022
2 parents 34119bb + 29e487f commit 3e1ffd2
Show file tree
Hide file tree
Showing 19 changed files with 128 additions and 96 deletions.
116 changes: 50 additions & 66 deletions packages/button/src/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,76 +54,60 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
const hasLoadingText =
loadingText != undefined && loadingText.length > 0
const hasChild = Children.count(props.children) >= 1
const hasPropContent = hasChild || (hasLoadingText && loading)
const finalContainer = css`
${applyTagContainer(fullWidth)};
${applyCursor(loading ?? false, disabled ?? false)}
${hasPropContent
? applyPaddingStyle(size, variant)
: applyWithoutTextSize(size, fullWidth)};
${applyShape(
shape,
attached ?? false,
first ?? false,
last ?? false,
)};
${applyElementColor(variant, colorScheme, textColor)};
${applyBg(variant, colorScheme, backgroundColor, borderColor)};
${buttonRadius ? `border-radius: ${buttonRadius};` : ""}
`

if (hasChild || (hasLoadingText && loading)) {
const finalContainer = css`
${applyTagContainer(fullWidth ?? false)};
${applyCursor(loading ?? false, disabled ?? false)}
${applyPaddingStyle(size, variant)};
${applyShape(
shape,
attached ?? false,
first ?? false,
last ?? false,
)};
${applyElementColor(variant, colorScheme, textColor)};
${applyBg(variant, colorScheme, backgroundColor, borderColor)};
`

return (
<button
ref={ref}
css={css(finalContainer, sizeCss)}
disabled={disabled || loading}
{...otherProps}
>
{(loading || leftIcon) && (
<span css={applyLeftIconStyle(size)}>
{loading ? <LoadingIcon spin={true} /> : leftIcon}
</span>
)}
return (
<button
ref={ref}
css={[finalContainer, sizeCss]}
disabled={disabled || loading}
{...otherProps}
>
{(loading || leftIcon) && (
<span
css={
hasPropContent
? applyLeftIconStyle(size)
: applyIconWithoutText(size)
}
>
{loading ? <LoadingIcon spin={true} /> : leftIcon}
</span>
)}
{hasPropContent && (
<span css={applyFontStyle(size)}>
{loading && loadingText ? loadingText : props.children}
</span>
{rightIcon && (
<span css={applyRightIconStyle(size)}>{rightIcon}</span>
)}
</button>
)
} else {
const finalContainer = css`
${applyTagContainer(fullWidth)};
${applyCursor(loading ?? false, disabled ?? false)}
${applyWithoutTextSize(size, fullWidth)};
${applyShape(
shape,
attached ?? false,
first ?? false,
last ?? false,
)};
${applyElementColor(variant, colorScheme, textColor)};
${applyBg(variant, colorScheme, backgroundColor, borderColor)};
${buttonRadius ? `border-radius: ${buttonRadius};` : ""}
`

return (
<button
ref={ref}
css={finalContainer}
disabled={disabled || loading}
{...otherProps}
>
{(loading || leftIcon) && (
<span css={applyIconWithoutText(size)}>
{loading ? <LoadingIcon spin={true} /> : leftIcon}
</span>
)}
{rightIcon && (
<span css={applyIconWithoutText(size)}>{rightIcon}</span>
)}
</button>
)
}
)}
{rightIcon && (
<span
css={
hasPropContent
? applyRightIconStyle(size)
: applyIconWithoutText(size)
}
>
{rightIcon}
</span>
)}
</button>
)
}}
</ButtonGroupContext.Consumer>
)
Expand Down
2 changes: 0 additions & 2 deletions packages/button/src/style.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ export function getDifferentStatusColor(
colorScheme: ButtonColorScheme,
variant: ButtonVariant,
state: State,
backgroundColor?: string,
borderColor?: string,
): string[] {
switch (state) {
case State.DEFAULT:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ exports[`Button Group renders attached with round shape 1`] = `
border-radius: 0;
color: #fff;
background-color: #134ae0;
width: auto;
height: auto;
}
.emotion-26:hover {
Expand Down Expand Up @@ -997,6 +999,8 @@ exports[`Button Group renders attached with square shape 1`] = `
border-radius: 0;
color: #fff;
background-color: #134ae0;
width: auto;
height: auto;
}
.emotion-26:hover {
Expand Down Expand Up @@ -1594,6 +1598,8 @@ exports[`Button Group renders with spacing 1`] = `
border-radius: 4px;
color: #fff;
background-color: #134ae0;
width: auto;
height: auto;
}
.emotion-26:hover {
Expand Down
16 changes: 12 additions & 4 deletions packages/date-picker/tests/date-picker.e2e.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,28 @@ it("show time picker, typeof showTime is Object, extends of TimePickerProps", ()
unmount()
})

it("clear data", () => {
mount(<DatePicker placeholder={"clear data"} value="2021-01-01" />)
/*it("clear data", () => {
const clearEvent = cy.stub().as("clearEvent")
mount(
<DatePicker
placeholder={"clear data"}
value="2021-01-01"
onClear={clearEvent}
/>,
)
cy.findByDisplayValue("2021-01-01")
.parent()
.trigger("mouseenter")
.then(() => {
cy.findByTitle("InputClearIcon")
.click()
.then(() => {
cy.findByDisplayValue("").should("exist")
cy.get("@clearEvent").should("be.calledOnce")
cy.get("input").should("not.have.value", "2021-01-01")
})
})
unmount()
})
})*/

it("click Today button", () => {
mount(
Expand Down
1 change: 1 addition & 0 deletions packages/modal/src/interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface ModalProps
extends Omit<HTMLAttributes<HTMLDivElement>, "title"> {
visible?: boolean
_css?: SerializedStyles
withoutPadding?: boolean
confirmLoading?: boolean
mask?: boolean
title?: ReactNode
Expand Down
20 changes: 11 additions & 9 deletions packages/modal/src/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const Modal: ModalComponent = forwardRef<HTMLDivElement, ModalProps>(
style,
className,
_css,
withoutPadding,
children,
visible,
mask = true,
Expand Down Expand Up @@ -119,16 +120,17 @@ export const Modal: ModalComponent = forwardRef<HTMLDivElement, ModalProps>(
<div css={applyModalTitle(simple)}>{title}</div>
</div>
)}
<div css={applyModalContent(simple)}>{children}</div>
<div css={applyModalContent(simple, withoutPadding)}>{children}</div>
{renderFooter()}
{showCloseIcon &&
(closeElement ? (
closeElement
) : (
<div css={applyModalCloseIcon} onClick={onCancel}>
<CloseIcon />
</div>
))}
{showCloseIcon && (
<>
{closeElement || (
<div css={applyModalCloseIcon} onClick={onCancel}>
<CloseIcon />
</div>
)}
</>
)}
</div>
)
return (
Expand Down
13 changes: 11 additions & 2 deletions packages/modal/src/style.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,15 @@ export function applyModalTitle(isSimple?: boolean): SerializedStyles {
`
}

export function applyModalContent(isSimple?: boolean): SerializedStyles {
export function applyModalContent(
isSimple?: boolean,
withoutPadding?: boolean,
): SerializedStyles {
const paddingCSS = withoutPadding
? css`
padding: 0;
`
: ""
const simpleCss = isSimple
? css`
padding: 0 24px 8px;
Expand All @@ -115,7 +123,8 @@ export function applyModalContent(isSimple?: boolean): SerializedStyles {
font-size: 14px;
overflow: auto;
color: ${globalColor(`--${illaPrefix}-grayBlue-02`)};
${simpleCss}
${simpleCss};
${paddingCSS}
`
}

Expand Down
11 changes: 11 additions & 0 deletions packages/modal/tests/modal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,14 @@ test("Modal api renders with config", () => {
Modal.config({ simple: true })
Modal.destroyAll()
})

test("Modal renders with withoutPadding ", () => {
render(
<Modal visible={true} title={"Modal Title"} withoutPadding>
Modal Content
</Modal>,
)
expect(screen.getByText("Modal Content")).toHaveStyle({
padding: "0px",
})
})
2 changes: 1 addition & 1 deletion packages/select/src/interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export interface SelectProps
export interface SelectViewProps
extends Omit<
SelectProps,
"options" | "filterOption" | "onChange" | "onClear"
"options" | "filterOption" | "onChange" | "onClear" | "triggerProps"
> {
value?: any
defaultValue?: any
Expand Down
9 changes: 1 addition & 8 deletions packages/select/src/select-view.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
forwardRef,
SyntheticEvent,
useEffect,
useReducer,
useRef,
useState,
} from "react"
import { forwardRef, SyntheticEvent, useEffect, useRef, useState } from "react"
import { InputElement, InputElementProps } from "@illa-design/input"
import { isNumber, isObject, omit } from "@illa-design/system"
import {
Expand Down
4 changes: 2 additions & 2 deletions packages/select/src/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
ReactText,
SyntheticEvent,
} from "react"
import { useMergeValue, isArray, isObject } from "@illa-design/system"
import { useMergeValue, isArray, isObject, omit } from "@illa-design/system"
import { Trigger } from "@illa-design/trigger"
import { SelectView } from "./select-view"
import {
Expand Down Expand Up @@ -373,7 +373,7 @@ export const Select = forwardRef<HTMLDivElement, SelectProps>((props, ref) => {
{...triggerProps}
>
<SelectView
{...props}
{...omit(props, ["triggerProps"])}
{...selectViewEventHandlers}
ref={ref}
value={currentValue}
Expand Down
11 changes: 10 additions & 1 deletion packages/system/src/use-merge-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function useMergeValue<T>(
},
): [T, React.Dispatch<React.SetStateAction<T>>, T] {
const { defaultValue, value } = props || {}
const firstRenderRef = useRef(true)
const firstRenderRef = useRef<boolean>()

const [stateValue, setStateValue] = useState<T>(
value !== undefined
Expand All @@ -19,6 +19,15 @@ export function useMergeValue<T>(
: defaultStateValue,
)

// fix:When StrictMode is enabled, React-18 intentionally double-invokes effects for newly mounted components
// link:https://github.com/reactwg/react-18/discussions/19
useEffect(() => {
firstRenderRef.current = true
return () => {
firstRenderRef.current = undefined
}
}, [])

useEffect(() => {
if (firstRenderRef.current) {
firstRenderRef.current = false
Expand Down
2 changes: 1 addition & 1 deletion packages/system/tests/system.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ test("System test padStart function", () => {

// test style.ts
test("GetStyle should work", () => {
render(<div style={{ color: "red" }} data-testid={"test"}></div>)
render(<div style={{ color: "red" }} data-testid={"test"} />)
expect(getStyle(screen.getByTestId("test"), "color")).toBe("red")
expect(getStyle(screen.getByTestId("test"), "")).toBe("")
})
Expand Down
1 change: 1 addition & 0 deletions packages/upload/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"dependencies": {
"@illa-design/icon": "0.0.4",
"@illa-design/image": "0.0.4",
"@illa-design/button": "0.0.4",
"@illa-design/list": "0.0.4",
"@illa-design/progress": "0.0.4",
"@illa-design/theme": "0.0.4",
Expand Down
2 changes: 2 additions & 0 deletions packages/upload/src/file-list-pic-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,5 @@ export const FileListPicItem = forwardRef<HTMLDivElement, FileListItemProps>(
)
},
)

FileListPicItem.displayName = "FileListPicItem"
2 changes: 2 additions & 0 deletions packages/upload/src/file-list-text-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,5 @@ export const FileListTextItem = forwardRef<HTMLDivElement, FileListItemProps>(
)
},
)

FileListTextItem.displayName = "FileListTextItem"
2 changes: 2 additions & 0 deletions packages/upload/src/upload-element.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,5 @@ export const UploadElement = forwardRef<UploadRefType, UploadInputElementProps>(
)
},
)

UploadElement.displayName = "UploadElement"
2 changes: 2 additions & 0 deletions packages/upload/src/upload-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,5 @@ export const UploadInput: FC<ChildrenNodeProps> = (props) => {
}
return autoUploadButton
}

UploadInput.displayName = "UploadInput"
2 changes: 2 additions & 0 deletions packages/upload/src/upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,5 @@ export const Upload = forwardRef<HTMLDivElement, UploadProps>((props, ref) => {
</div>
)
})

Upload.displayName = "Upload"

0 comments on commit 3e1ffd2

Please sign in to comment.