enhance(compo):调整可激活链接中的默认属性处理。
This commit is contained in:
parent
c0815b0a21
commit
fceeb92c06
|
@ -1,6 +1,6 @@
|
|||
import { A } from "@solidjs/router";
|
||||
import { defaultTo, isNil, pick, pipe, prop } from "ramda";
|
||||
import { Show } from "solid-js";
|
||||
import { Show, mergeProps } from "solid-js";
|
||||
import classes from "./ActivatableLink.module.css";
|
||||
|
||||
/**
|
||||
|
@ -24,17 +24,21 @@ const defaultActivatable = pipe(defaultTo(true), prop("activatable"));
|
|||
* @returns {import("solid-js").Component<ActivatableLinkProps>}
|
||||
*/
|
||||
export default function ActivatableLink(props) {
|
||||
const mergedProps = mergeProps(
|
||||
{ activatable: true, leftIcon: null, rightIcon: null },
|
||||
props
|
||||
);
|
||||
return (
|
||||
<A
|
||||
class={prop("activatable-link", classes)}
|
||||
{...(defaultActivatable(props) && {
|
||||
{...(prop("activatable", mergedProps) && {
|
||||
activeClass: "activated",
|
||||
})}
|
||||
{...pick(["replace", "end", "href"], props)}
|
||||
{...pick(["replace", "end", "href"], mergedProps)}
|
||||
>
|
||||
<Show when={!isNil(props.leftIcon)}>{props.leftIcon}</Show>
|
||||
<Show when={!isNil(props.children)}>{props.children}</Show>
|
||||
<Show when={!isNil(props.rightIcon)}>{props.rightIcon}</Show>
|
||||
<Show when={!isNil(mergedProps.leftIcon)}>{mergedProps.leftIcon}</Show>
|
||||
<Show when={!isNil(mergedProps.children)}>{mergedProps.children}</Show>
|
||||
<Show when={!isNil(mergedProps.rightIcon)}>{mergedProps.rightIcon}</Show>
|
||||
</A>
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user