mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-02 03:58:07 +08:00
feat: loading根据父级背景颜色自动适配颜色 (#9507)
Co-authored-by: qinhaoyan <30946345+qinhaoyan@users.noreply.github.com>
This commit is contained in:
parent
70c8d300e4
commit
5115bc73fa
@ -3308,6 +3308,7 @@
|
|||||||
--Spinner-width: var(--spinner-size-size);
|
--Spinner-width: var(--spinner-size-size);
|
||||||
--Spinner-color: var(--spinner-base-color);
|
--Spinner-color: var(--spinner-base-color);
|
||||||
--Spinner-color--disabled: rgba(0, 0, 0, 0.65);
|
--Spinner-color--disabled: rgba(0, 0, 0, 0.65);
|
||||||
|
--loading-dark-bg-color: var(--colors-neutral-text-11);
|
||||||
|
|
||||||
// Image
|
// Image
|
||||||
--image-image-normal-paddingTop: var(--sizes-size-3);
|
--image-image-normal-paddingTop: var(--sizes-size-3);
|
||||||
|
@ -105,6 +105,12 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.#{$ns}Spinner-icon--darkBg {
|
||||||
|
svg.icon path {
|
||||||
|
fill: var(--loading-dark-bg-color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.#{$ns}Spinner-tip {
|
.#{$ns}Spinner-tip {
|
||||||
margin: px2rem(12px) 0 0 0;
|
margin: px2rem(12px) 0 0 0;
|
||||||
word-break: keep-all;
|
word-break: keep-all;
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
:root,
|
:root,
|
||||||
.AMISCSSWrapper {
|
.AMISCSSWrapper {
|
||||||
|
--loading-dark-bg-color: var(--colors-neutral-fill-2);
|
||||||
--switch-text-on-color: var(--colors-neutral-text-2);
|
--switch-text-on-color: var(--colors-neutral-text-2);
|
||||||
--switch-text-off-color: var(--colors-neutral-text-2);
|
--switch-text-off-color: var(--colors-neutral-text-2);
|
||||||
--switch-default-on-slider-color: var(--colors-neutral-fill-2);
|
--switch-default-on-slider-color: var(--colors-neutral-fill-2);
|
||||||
|
@ -104,7 +104,7 @@ const store = SpinnerSharedStore.create({});
|
|||||||
|
|
||||||
export class Spinner extends React.Component<
|
export class Spinner extends React.Component<
|
||||||
SpinnerProps,
|
SpinnerProps,
|
||||||
{spinning: boolean; showMarker: boolean}
|
{spinning: boolean; showMarker: boolean; idDarkBg: boolean}
|
||||||
> {
|
> {
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
show: true,
|
show: true,
|
||||||
@ -122,7 +122,8 @@ export class Spinner extends React.Component<
|
|||||||
|
|
||||||
state = {
|
state = {
|
||||||
spinning: false,
|
spinning: false,
|
||||||
showMarker: true
|
showMarker: true,
|
||||||
|
idDarkBg: false
|
||||||
};
|
};
|
||||||
|
|
||||||
parent: HTMLElement | null = null;
|
parent: HTMLElement | null = null;
|
||||||
@ -159,6 +160,19 @@ export class Spinner extends React.Component<
|
|||||||
if (this.parent && this.state.showMarker) {
|
if (this.parent && this.state.showMarker) {
|
||||||
this.setState({showMarker: false});
|
this.setState({showMarker: false});
|
||||||
}
|
}
|
||||||
|
if (this.parent) {
|
||||||
|
const backgroundColor = getComputedStyle(this.parent).getPropertyValue(
|
||||||
|
'background-color'
|
||||||
|
);
|
||||||
|
const rgba = backgroundColor.match(/\d+/g)?.map(Number) || [];
|
||||||
|
|
||||||
|
const brightness = (rgba[0] * 299 + rgba[1] * 587 + rgba[2] * 114) / 1000;
|
||||||
|
rgba[3] = rgba[3] ?? 1; // 没有设置颜色时取到的是 rgba(0, 0, 0, 0)
|
||||||
|
|
||||||
|
if (brightness < 200 && rgba[3] > 0.4) {
|
||||||
|
this.setState({idDarkBg: true});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
@ -250,7 +264,8 @@ export class Spinner extends React.Component<
|
|||||||
'Spinner-icon--custom': isCustomIcon,
|
'Spinner-icon--custom': isCustomIcon,
|
||||||
'Spinner-icon--disabled': disabled
|
'Spinner-icon--disabled': disabled
|
||||||
},
|
},
|
||||||
spinnerClassName
|
spinnerClassName,
|
||||||
|
this.state.idDarkBg && 'Spinner-icon--darkBg'
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{icon ? (
|
{icon ? (
|
||||||
|
Loading…
Reference in New Issue
Block a user