Skip to content

Commit b742645

Browse files
committed
VanUI 0.9.1: Support customized class and style overrides for cross button when it's hovered over
1 parent 5af4f91 commit b742645

25 files changed

+152
-78
lines changed

components/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,20 @@ van.add(document.body, FloatingWindow(
488488
))
489489
```
490490

491+
Window with customized close button:
492+
493+
```ts
494+
van.add(document.body, FloatingWindow(
495+
{
496+
title: "Example Window 3", x: 175, y: 175, closeCross: "❌",
497+
crossHoverStyleOverrides: {"background-color": "transparent"},
498+
},
499+
div({style: "display: flex; justify-content: center;"},
500+
p("This is a floating window with custom cross button!"),
501+
),
502+
))
503+
```
504+
491505
Window with `Tabs` and custom close button:
492506

493507
```ts
@@ -645,6 +659,8 @@ You can override the default stacking behavior by specifying `{customStacking: t
645659
* `childrenContainerStyleOverrides`: Type `Record<string, string | number>`. Default `{}`. Optional. A [property bag](#property-bag-for-style-overrides) for the styles you want to override for the container of `children` DOM nodes.
646660
* `crossClass`: Type `string`. Default `""`. Optional. The `class` attribute of the close button. You can specify multiple CSS classes separated by `" "`.
647661
* `crossStyleOverrides`: Type `Record<string, string | number>`. Default `{}`. Optional. A [property bag](#property-bag-for-style-overrides) for the styles you want to override for the close button.
662+
* `crossHoverClass`: Type `string`. Default `""`. Optional. The `class` attribute of the close button when it's hovered over. You can specify multiple CSS classes separated by `" "`.
663+
* `crossStyleOverrides`: Type `Record<string, string | number>`. Default `{}`. Optional. A [property bag](#property-bag-for-style-overrides) for the styles you want to override for the close button when it's hovered over.
648664

649665
### Property Bag for Style Overrides
650666

components/dist/van-ui.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ export interface FloatingWindowProps {
130130
readonly childrenContainerStyleOverrides?: CSSPropertyBag;
131131
readonly crossClass?: string;
132132
readonly crossStyleOverrides?: CSSPropertyBag;
133+
readonly crossHoverClass?: string;
134+
readonly crossHoverStyleOverrides?: CSSPropertyBag;
133135
}
134136
export declare const topMostZIndex: () => number;
135-
export declare const FloatingWindow: ({ title, closed, x, y, width, height, closeCross, customStacking, zIndex, disableMove, disableResize, headerColor, windowClass, windowStyleOverrides, headerClass, headerStyleOverrides, childrenContainerClass, childrenContainerStyleOverrides, crossClass, crossStyleOverrides, }: FloatingWindowProps, ...children: readonly ChildDom[]) => () => HTMLDivElement | null;
137+
export declare const FloatingWindow: ({ title, closed, x, y, width, height, closeCross, customStacking, zIndex, disableMove, disableResize, headerColor, windowClass, windowStyleOverrides, headerClass, headerStyleOverrides, childrenContainerClass, childrenContainerStyleOverrides, crossClass, crossStyleOverrides, crossHoverClass, crossHoverStyleOverrides, }: FloatingWindowProps, ...children: readonly ChildDom[]) => () => HTMLDivElement | null;

components/dist/van-ui.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ export const Banner = ({ backgroundColor = "#fff1a8", fontColor = "currentcolor"
248248
};
249249
let curWindowZIndex = 0;
250250
export const topMostZIndex = () => ++curWindowZIndex;
251-
export const FloatingWindow = ({ title, closed = van.state(false), x = 100, y = 100, width = 300, height = 200, closeCross = "×", customStacking = false, zIndex = 1, disableMove = false, disableResize = false, headerColor = "lightgray", windowClass = "", windowStyleOverrides = {}, headerClass = "", headerStyleOverrides = {}, childrenContainerClass = "", childrenContainerStyleOverrides = {}, crossClass = "", crossStyleOverrides = {}, }, ...children) => {
251+
export const FloatingWindow = ({ title, closed = van.state(false), x = 100, y = 100, width = 300, height = 200, closeCross = "×", customStacking = false, zIndex = 1, disableMove = false, disableResize = false, headerColor = "lightgray", windowClass = "", windowStyleOverrides = {}, headerClass = "", headerStyleOverrides = {}, childrenContainerClass = "", childrenContainerStyleOverrides = {}, crossClass = "", crossStyleOverrides = {}, crossHoverClass = "", crossHoverStyleOverrides = {}, }, ...children) => {
252252
const xState = stateOf(x), yState = stateOf(y);
253253
const widthState = stateOf(width), heightState = stateOf(height);
254254
const zIndexState = stateOf(zIndex);
@@ -257,6 +257,8 @@ export const FloatingWindow = ({ title, closed = van.state(false), x = 100, y =
257257
const dragging = van.state(false), resizingDirection = van.state(null);
258258
const startX = van.state(0), startY = van.state(0);
259259
const startWidth = van.state(0), startHeight = van.state(0);
260+
const crossHover = crossHoverClass || Object.keys(crossHoverStyleOverrides) ?
261+
van.state(false) : null;
260262
const onmousedown = (e) => {
261263
if (e.button !== 0)
262264
return;
@@ -390,9 +392,20 @@ export const FloatingWindow = ({ title, closed = van.state(false), x = 100, y =
390392
}),
391393
...(disableMove ? {} : { onmousedown }),
392394
}, title, closeCross ? span({
393-
class: ["vanui-window-cross"].concat(crossClass ? crossClass : []).join(" "),
394-
style: toStyleStr(crossStyleOverrides),
395+
class: () => ["vanui-window-cross"]
396+
.concat(crossClass ? crossClass : [])
397+
.concat(crossHoverClass && crossHover.val ? crossHoverClass : [])
398+
.join(" "),
399+
style: () => toStyleStr({
400+
...crossStyleOverrides,
401+
...(Object.keys(crossHoverStyleOverrides).length && crossHover.val ?
402+
crossHoverStyleOverrides : {}),
403+
}),
395404
onclick: () => closed.val = true,
405+
...(crossHover ? {
406+
onmouseenter: () => crossHover.val = true,
407+
onmouseleave: () => crossHover.val = false,
408+
} : {})
396409
}, closeCross) : null) : disableMove ? null : div({
397410
class: "vanui-window-dragarea",
398411
onmousedown,

components/dist/van-ui.nomodule.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@
248248
};
249249
let curWindowZIndex = 0;
250250
window.topMostZIndex = () => ++curWindowZIndex;
251-
window.FloatingWindow = ({ title, closed = van.state(false), x = 100, y = 100, width = 300, height = 200, closeCross = "×", customStacking = false, zIndex = 1, disableMove = false, disableResize = false, headerColor = "lightgray", windowClass = "", windowStyleOverrides = {}, headerClass = "", headerStyleOverrides = {}, childrenContainerClass = "", childrenContainerStyleOverrides = {}, crossClass = "", crossStyleOverrides = {}, }, ...children) => {
251+
window.FloatingWindow = ({ title, closed = van.state(false), x = 100, y = 100, width = 300, height = 200, closeCross = "×", customStacking = false, zIndex = 1, disableMove = false, disableResize = false, headerColor = "lightgray", windowClass = "", windowStyleOverrides = {}, headerClass = "", headerStyleOverrides = {}, childrenContainerClass = "", childrenContainerStyleOverrides = {}, crossClass = "", crossStyleOverrides = {}, crossHoverClass = "", crossHoverStyleOverrides = {}, }, ...children) => {
252252
const xState = stateOf(x), yState = stateOf(y);
253253
const widthState = stateOf(width), heightState = stateOf(height);
254254
const zIndexState = stateOf(zIndex);
@@ -257,6 +257,8 @@
257257
const dragging = van.state(false), resizingDirection = van.state(null);
258258
const startX = van.state(0), startY = van.state(0);
259259
const startWidth = van.state(0), startHeight = van.state(0);
260+
const crossHover = crossHoverClass || Object.keys(crossHoverStyleOverrides) ?
261+
van.state(false) : null;
260262
const onmousedown = (e) => {
261263
if (e.button !== 0)
262264
return;
@@ -390,9 +392,20 @@
390392
}),
391393
...(disableMove ? {} : { onmousedown }),
392394
}, title, closeCross ? span({
393-
class: ["vanui-window-cross"].concat(crossClass ? crossClass : []).join(" "),
394-
style: toStyleStr(crossStyleOverrides),
395+
class: () => ["vanui-window-cross"]
396+
.concat(crossClass ? crossClass : [])
397+
.concat(crossHoverClass && crossHover.val ? crossHoverClass : [])
398+
.join(" "),
399+
style: () => toStyleStr({
400+
...crossStyleOverrides,
401+
...(Object.keys(crossHoverStyleOverrides).length && crossHover.val ?
402+
crossHoverStyleOverrides : {}),
403+
}),
395404
onclick: () => closed.val = true,
405+
...(crossHover ? {
406+
onmouseenter: () => crossHover.val = true,
407+
onmouseleave: () => crossHover.val = false,
408+
} : {})
396409
}, closeCross) : null) : disableMove ? null : div({
397410
class: "vanui-window-dragarea",
398411
onmousedown,

components/dist/van-ui.nomodule.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/examples/banner/package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/examples/banner/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
},
1616
"dependencies": {
1717
"vanjs-core": "^1.2.5",
18-
"vanjs-ui": "^0.9.0"
18+
"vanjs-ui": "^0.9.1"
1919
}
2020
}

components/examples/message/package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/examples/message/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
},
1616
"dependencies": {
1717
"vanjs-core": "^1.2.5",
18-
"vanjs-ui": "^0.9.0"
18+
"vanjs-ui": "^0.9.1"
1919
}
2020
}

components/examples/modal/package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)