Skip to content

Commit

Permalink
feat: add active slot-scope.
Browse files Browse the repository at this point in the history
  • Loading branch information
chizukicn committed Apr 27, 2023
1 parent 6646cbd commit 25d2ea1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
11 changes: 6 additions & 5 deletions packages/hoci/src/components/selection/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,15 @@ export const selectionItemProps = defineHookProps({
export const useSelectionItem = defineHookComponent({
props: selectionItemProps,
setup(props, { slots }) {
const isActive = inject(IsActiveSymbol, () => false);
const changeActive = inject(ChangeActiveSymbol, () => {});

const parentLabel = resolveRef(inject(ItemLabelSymbol));

function render() {
return renderSlot(slots, "default", {}, () => {
return renderSlot(slots, "default", {
active: isActive(props.value)
}, () => {
let label = props.label ?? parentLabel.value;
if (label) {
if (typeof label == "function") {
Expand Down Expand Up @@ -84,10 +89,6 @@ export const useSelectionItem = defineHookComponent({
onDeactivated(() => remove());
}

const isActive = inject(IsActiveSymbol, () => false);

const changeActive = inject(ChangeActiveSymbol, () => {});

const activeClass = computed(
() => inject(ActiveClassSymbol)?.value ?? "active"
);
Expand Down
4 changes: 3 additions & 1 deletion packages/hoci/src/components/selection/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ export const useSelectionList = defineHookComponent({
}

function render() {
return h(props.tag, {}, renderSlot(slots, "default", {}));
return h(props.tag, {}, renderSlot(slots, "default", {
isActive
}));
}

return {
Expand Down
8 changes: 5 additions & 3 deletions packages/hoci/src/components/switch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ export const useSwitch = defineHookComponent({
});

export const HiSwitch = defineComponent({
name: "ISwitch",
name: "HiSwitch",
props: switchProps,
emits: switchEmits,

setup(props, context) {
const { slots } = context;
const { switchClass, toggle } = useSwitch(props, context);
const { switchClass, toggle, modelValue } = useSwitch(props, context);

return () => {
return h(
Expand All @@ -99,7 +99,9 @@ export const HiSwitch = defineComponent({
class: switchClass.value,
[`on${capitalize(props.activateEvent)}`]: toggle
},
renderSlot(slots, "default")
renderSlot(slots, "default", {
active: modelValue.value
})
);
};
}
Expand Down

0 comments on commit 25d2ea1

Please sign in to comment.