overlayscrollbars-react 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,30 @@
1
+ # Changelog
2
+
3
+ ## 0.5.0
4
+
5
+ ### Features
6
+
7
+ Added the possibility to `defer` the initialization to a point in time when the browser is idle. (or to the next frame if `window.requestIdleCallback` is not supported)
8
+ - `OverlayScrollbarsComponent` accepts now the `defer` property
9
+ - `useOverlayScrollbars` params accept now the `defer` key
10
+ - `useOverlayScrollbars` will now always try to destroy the instance if the component unmounts.
11
+
12
+ ### Breaking Changes
13
+
14
+ - Because initialization can be deferred now, the `initialize` function of the `useOverlayScrollbars` hook isn't returning the instance anymore. Use the `instance` function of the `useOverlayScrollbars` hook instead.
15
+
16
+ ## 0.4.0
17
+
18
+ Depends on `OverlayScrollbars` version `^2.0.0` and `React` version `>=16.8.0`.
19
+ The component was rewritten using `hooks`. ([#218](https://github.com/KingSora/OverlayScrollbars/pull/218))
20
+
21
+ ### Features
22
+
23
+ - `OverlayScrollbarsComponent` accepts now the `events` property
24
+ - `OverlayScrollbarsComponent` accepts now the `element` property
25
+ - The `useOverlayScrollbars` hook was added for advanced usage
26
+
27
+ ### Breaking Changes
28
+
29
+ - The `extensions` property is removed from `OverlayScrollbarsComponent`
30
+ - The `osTarget()` function from the `OverlayScrollbarsComponent` `ref` is renamed to `getElement()`
package/README.md CHANGED
@@ -1,123 +1,141 @@
1
- <p align="center">
2
- <a href="https://reactjs.org/"><img src="https://kingsora.github.io/OverlayScrollbars/frameworks/react/logo.svg" width="200" height="133" alt="React"></a>
3
- <a href="https://kingsora.github.io/OverlayScrollbars/"><img src="https://kingsora.github.io/OverlayScrollbars/design/logo.svg" width="200" height="133" alt="OverlayScrollbars"></a>
4
- </p>
5
- <h6 align="center">
6
- <a href="https://github.com/facebook/react/"><img src="https://img.shields.io/badge/React-%3E=16.4.0-61dafb?style=flat-square&logo=React" alt="React"></a>
7
- <a href="https://github.com/KingSora/OverlayScrollbars"><img src="https://img.shields.io/badge/OverlayScrollbars-%5E1.10.0-36befd?style=flat-square" alt="OverlayScrollbars"></a>
8
- <a href="https://www.npmjs.com/package/overlayscrollbars-react"><img src="https://img.shields.io/npm/dt/overlayscrollbars-react.svg?style=flat-square" alt="Downloads"></a>
9
- <a href="https://github.com/KingSora/OverlayScrollbars/blob/master/packages/overlayscrollbars-react/LICENSE"><img src="https://img.shields.io/github/license/kingsora/overlayscrollbars.svg?style=flat-square" alt="License"></a>
10
- </h6>
11
- <h3 align="center">
12
- <a href="https://kingsora.github.io/OverlayScrollbars/frameworks/react/">Example</a>
13
- &nbsp;&nbsp;&bull;&nbsp;&nbsp;
14
- <a href="https://kingsora.github.io/OverlayScrollbars/#!documentation">Documentation</a>
15
- &nbsp;&nbsp;&bull;&nbsp;&nbsp;
16
- <a href="https://kingsora.github.io/OverlayScrollbars/#!faq">FAQ</a>
17
- </h3>
18
- <h5 align="center">
19
- The official OverlayScrollbars wrapper for React.
20
- </h5>
21
-
22
- ## Installation
23
-
24
- ```sh
25
- npm install overlayscrollbars-react
26
- ```
27
-
28
- ## Peer Dependencies
29
-
30
- OverlayScrollbars for React has the following **peer dependencies**:
31
-
32
- - The vanilla JavaScript library: [overlayscrollbars](https://www.npmjs.com/package/overlayscrollbars)
33
-
34
- ```
35
- npm install overlayscrollbars
36
- ```
37
-
38
- - The React framework: [react](https://www.npmjs.com/package/react)
39
-
40
- ```
41
- npm install react
42
- ```
43
-
44
- ## TypeScript
45
-
46
- - In case you are using TypeScript, you have to install the [OverlayScrollbars typings](https://www.npmjs.com/package/@types/overlayscrollbars):
47
-
48
- ```
49
- npm install @types/overlayscrollbars
50
- ```
51
-
52
- Since this wrapper is written in TypeScript it comes with its generated typings.<br>
53
- Check out the [recommended](https://github.com/KingSora/OverlayScrollbars#typescript) **tsconfig.json** options.
54
-
55
- ## Usage
56
-
57
- #### CSS
58
-
59
- You have to import the `OverlayScrollbars.css` by yourself.<br>
60
- The component **doesn't** do it for you as the styles are **global styles**!<br>
61
- There are different ways to achieve this, in React the most simple way for me was to add [this line](https://github.com/KingSora/OverlayScrollbars/blob/master/packages/overlayscrollbars-react/example/src/index.tsx#L1) in the `index` file:
62
-
63
- ```js
64
- import "overlayscrollbars/css/OverlayScrollbars.css";
65
- ```
66
-
67
- #### Import
68
-
69
- Simply import the component into your file(s):
70
-
71
- ```js
72
- import { OverlayScrollbarsComponent } from "overlayscrollbars-react";
73
- ```
74
-
75
- #### Template
76
-
77
- After the import you can use it in JSX:
78
-
79
- ```jsx
80
- <OverlayScrollbarsComponent>example content</OverlayScrollbarsComponent>
81
- ```
82
-
83
- #### Properties
84
-
85
- Two properties are accepted: `options` and `extensions`.
86
-
87
- - The `options` property accepts a `object` and can be changed at any point in time, and the plugin will adapt.
88
- - The `extensions` property accepts a `string`, `string array` or `object` and is only taken into account if the component gets mounted.
89
-
90
- ```jsx
91
- <OverlayScrollbarsComponent
92
- options={{ scrollbars: { autoHide: "scroll" } }}
93
- extensions={["extensionA", "extensionB"]}
94
- ></OverlayScrollbarsComponent>
95
- ```
96
-
97
- You can read more about the `options` object [here](https://kingsora.github.io/OverlayScrollbars/#!documentation/options), `extensions` are documented [here](https://kingsora.github.io/OverlayScrollbars/#!documentation/extensions-basics) and [here](https://kingsora.github.io/OverlayScrollbars/#!documentation/initialization).
98
-
99
- #### Instance
100
-
101
- If you get the component reference, it provides two methods: `osInstance()` and `osTarget()`.
102
-
103
- - The `osInstance()` method returns the OverlayScrollbars `instance` of the component, or `null` if the instance isn't initialized yet or already destroyed.
104
- - The `osTarget()` method returns the native `html` element to which the plugin was initialized, or `null` if the the component isn't mounted yet or already unmounted.
105
-
106
- ## Example App
107
-
108
- In case you need a example app for reference, you can use the example app in this repo(`example folder`):
109
-
110
- - [Live example](https://kingsora.github.io/OverlayScrollbars/frameworks/react/)
111
- - [Source code](https://github.com/KingSora/OverlayScrollbars/tree/master/packages/overlayscrollbars-react/example)
112
-
113
- If you wanna build the example app, run these commands:
114
-
115
- ```sh
116
- npm run setup
117
- npm run build
118
- npm run example
119
- ```
120
-
121
- ## License
122
-
123
- MIT
1
+ <div align="center">
2
+ <a href="https://kingsora.github.io/OverlayScrollbars"><img src="https://raw.githubusercontent.com/KingSora/OverlayScrollbars/master/logo/logo.png" width="160" height="160" alt="OverlayScrollbars"></a>
3
+ <a href="https://reactjs.org"><img src="https://raw.githubusercontent.com/KingSora/OverlayScrollbars/master/packages/overlayscrollbars-react/logo.svg" width="160" height="160" alt="React"></a>
4
+ </div>
5
+ <br />
6
+ <div align="center">
7
+
8
+ [![OverlayScrollbars](https://img.shields.io/badge/OverlayScrollbars-%5E2.0.0-338EFF?style=flat-square)](https://github.com/KingSora/OverlayScrollbars)
9
+ [![React](https://img.shields.io/badge/React-%3E=16.8.0-61DAFB?style=flat-square&logo=React)](https://github.com/facebook/react/)
10
+ [![Downloads](https://img.shields.io/npm/dt/overlayscrollbars-react.svg?style=flat-square)](https://www.npmjs.com/package/overlayscrollbars-react)
11
+ [![Version](https://img.shields.io/npm/v/overlayscrollbars-react.svg?style=flat-square)](https://www.npmjs.com/package/overlayscrollbars-react)
12
+ [![License](https://img.shields.io/github/license/kingsora/overlayscrollbars.svg?style=flat-square)](#)
13
+
14
+ </div>
15
+
16
+ # OverlayScrollbars for React
17
+
18
+ This is the official OverlayScrollbars React wrapper.
19
+
20
+ ## Installation
21
+
22
+ ```sh
23
+ npm install overlayscrollbars-react
24
+ ```
25
+
26
+ ## Peer Dependencies
27
+
28
+ OverlayScrollbars for React has the following **peer dependencies**:
29
+
30
+ - The vanilla JavaScript library: [overlayscrollbars](https://www.npmjs.com/package/overlayscrollbars)
31
+
32
+ ```
33
+ npm install overlayscrollbars
34
+ ```
35
+
36
+ - The React framework: [react](https://www.npmjs.com/package/react)
37
+
38
+ ```
39
+ npm install react
40
+ ```
41
+
42
+ ## Usage
43
+
44
+ The first step is to import the CSS file into your app:
45
+ ```ts
46
+ import 'overlayscrollbars/overlayscrollbars.css';
47
+ ```
48
+
49
+ > __Note__: In older node versions use `'overlayscrollbars/styles/overlayscrollbars.css'` as the import path for the CSS file.
50
+
51
+ ## Component
52
+
53
+ The main entry point is the `OverlayScrollbarsComponent` which can be used in your application as a component:
54
+
55
+ ```jsx
56
+ import { OverlayScrollbarsComponent } from "overlayscrollbars-react";
57
+
58
+ // ...
59
+
60
+ <OverlayScrollbarsComponent defer>
61
+ example content
62
+ </OverlayScrollbarsComponent>
63
+ ```
64
+
65
+ ### Properties
66
+
67
+ The component accepts all properties of intrinsic JSX elements such as `div` and `span`.
68
+ Additionally it has three optional properties: `element`, `options` and `events`.
69
+
70
+ - `element`: accepts a `string` which represents the tag of the root element.
71
+ - `options`: accepts an `object` which represents the OverlayScrollbars options.
72
+ - `events`: accepts an `object` which represents the OverlayScrollbars events.
73
+ - `defer`: accepts an `boolean` or `object`. Defers the initialization to a point in time when the browser is idle.
74
+
75
+ > __Note__: None of the properties has to be memoized.
76
+
77
+ > __Note__: Its **highly recommended** to use the `defer` option whenever possible to defer the initialization to a browser's idle period.
78
+
79
+ ```jsx
80
+ // example usage
81
+ <OverlayScrollbarsComponent
82
+ element="span"
83
+ options={{ scrollbars: { autoHide: 'scroll' } }}
84
+ events={{ scroll: () => { /* ... */ } }}
85
+ defer
86
+ />
87
+ ```
88
+
89
+ ### Ref
90
+
91
+ The `ref` of the `OverlayScrollbarsComponent` will give you an object with which you can access the OverlayScrollbars `instance` and the root `element` of the component.
92
+ The ref object has two properties:
93
+
94
+ - `osInstance`: a function which returns the OverlayScrollbars instance.
95
+ - `getElement`: a function which returns the root element.
96
+
97
+ ## Hook
98
+
99
+ In case the `OverlayScrollbarsComponent` is not enough, you can also use the `useOverlayScrollbars` hook:
100
+
101
+ ```jsx
102
+ import { useOverlayScrollbars } from "overlayscrollbars-react";
103
+
104
+ // example usage
105
+ const Component = () => {
106
+ const ref = useRef();
107
+ const [initialize, instance] = useOverlayScrollbars({ options, events, defer });
108
+
109
+ useEffect(() => {
110
+ initialize(ref.current);
111
+ }, [initialize]);
112
+
113
+ return <div ref={ref} />
114
+ }
115
+ ```
116
+
117
+ The hook is for advanced usage and lets you control the whole initialization process. This is useful if you want to integrate it with other plugins such as `react-window` or `react-virtualized`.
118
+
119
+ The hook will destroy the instance automatically if the component unmounts.
120
+
121
+ ### Parameters
122
+
123
+ Parameters are optional and similar to the `OverlayScrollbarsComponent`.
124
+ Its an `object` with two optional properties:
125
+
126
+ - `options`: accepts an `object` which represents the OverlayScrollbars options.
127
+ - `events`: accepts an `object` which represents the OverlayScrollbars events.
128
+ - `defer`: accepts an `boolean` or `object`. Defers the initialization to a point in time when the browser is idle.
129
+
130
+ ### Return
131
+
132
+ The `useOverlayScrollbars` hook returns a `tuple` with two values:
133
+
134
+ - The first value is the `initialization` function, it takes one argument which is the `InitializationTarget`.
135
+ - The second value is a function which returns the current OverlayScrollbars instance or `null` if not initialized.
136
+
137
+ > __Note__: The identity of both functions is stable and won't change, thus they can safely be used in any dependency array.
138
+
139
+ ## License
140
+
141
+ MIT
@@ -0,0 +1,86 @@
1
+ import b, { useMemo as w, useRef as f, useEffect as v, forwardRef as C, useImperativeHandle as E } from "react";
2
+ import { OverlayScrollbars as R } from "overlayscrollbars";
3
+ const O = () => {
4
+ if (typeof window > "u") {
5
+ const n = () => {
6
+ };
7
+ return [n, n];
8
+ }
9
+ let l, c;
10
+ const t = window, o = typeof t.requestIdleCallback == "function", a = t.requestAnimationFrame, i = t.cancelAnimationFrame, r = o ? t.requestIdleCallback : a, u = o ? t.cancelIdleCallback : i, s = () => {
11
+ u(l), i(c);
12
+ };
13
+ return [
14
+ (n, e) => {
15
+ s(), l = r(
16
+ o ? () => {
17
+ s(), c = a(n);
18
+ } : n,
19
+ typeof e == "object" ? e : { timeout: 2233 }
20
+ );
21
+ },
22
+ s
23
+ ];
24
+ }, S = (l) => {
25
+ const { options: c, events: t, defer: o } = l || {}, [a, i] = w(O, []), r = f(null), u = f(o), s = f(c), n = f(t);
26
+ return v(() => {
27
+ u.current = o;
28
+ }, [o]), v(() => {
29
+ const { current: e } = r;
30
+ s.current = c, R.valid(e) && e.options(c || {}, !0);
31
+ }, [c]), v(() => {
32
+ const { current: e } = r;
33
+ n.current = t, R.valid(e) && e.on(t || {}, !0);
34
+ }, [t]), v(
35
+ () => () => {
36
+ var e;
37
+ i(), (e = r.current) == null || e.destroy();
38
+ },
39
+ []
40
+ ), w(
41
+ () => [
42
+ (e) => {
43
+ const y = r.current;
44
+ if (R.valid(y))
45
+ return;
46
+ const d = u.current, I = s.current || {}, m = n.current || {}, p = () => r.current = R(e, I, m);
47
+ d ? a(p, d) : p();
48
+ },
49
+ () => r.current
50
+ ],
51
+ []
52
+ );
53
+ }, F = (l, c) => {
54
+ const { element: t = "div", options: o, events: a, defer: i, children: r, ...u } = l, s = t, n = f(null), e = f(null), [y, d] = S({ options: o, events: a, defer: i });
55
+ return v(() => {
56
+ const { current: I } = n, { current: m } = e;
57
+ return I && m && y({
58
+ target: I,
59
+ elements: {
60
+ viewport: m,
61
+ content: m
62
+ }
63
+ }), () => {
64
+ var p;
65
+ return (p = d()) == null ? void 0 : p.destroy();
66
+ };
67
+ }, [y, t]), E(
68
+ c,
69
+ () => ({
70
+ osInstance: d,
71
+ getElement: () => n.current
72
+ }),
73
+ []
74
+ ), /* @__PURE__ */ b.createElement(s, {
75
+ "data-overlayscrollbars-initialize": "",
76
+ ref: n,
77
+ ...u
78
+ }, /* @__PURE__ */ b.createElement("div", {
79
+ ref: e
80
+ }, r));
81
+ }, A = C(F);
82
+ export {
83
+ A as OverlayScrollbarsComponent,
84
+ S as useOverlayScrollbars
85
+ };
86
+ //# sourceMappingURL=overlayscrollbars-react.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"overlayscrollbars-react.es.js","sources":["../src/useOverlayScrollbars.ts","../src/OverlayScrollbarsComponent.tsx"],"sourcesContent":["import { useEffect, useMemo, useRef } from 'react';\r\nimport { OverlayScrollbars } from 'overlayscrollbars';\r\nimport type { InitializationTarget } from 'overlayscrollbars';\r\nimport type {\r\n OverlayScrollbarsComponentProps,\r\n OverlayScrollbarsComponentRef,\r\n} from './OverlayScrollbarsComponent';\r\n\r\ntype Defer = [\r\n requestDefer: (callback: () => any, options?: OverlayScrollbarsComponentProps['defer']) => void,\r\n cancelDefer: () => void\r\n];\r\n\r\nexport interface UseOverlayScrollbarsParams {\r\n /** OverlayScrollbars options. */\r\n options?: OverlayScrollbarsComponentProps['options'];\r\n /** OverlayScrollbars events. */\r\n events?: OverlayScrollbarsComponentProps['events'];\r\n /** Whether to defer the initialization to a point in time when the browser is idle. (or to the next frame if `window.requestIdleCallback` is not supported) */\r\n defer?: OverlayScrollbarsComponentProps['defer'];\r\n}\r\n\r\nexport type UseOverlayScrollbarsInitialization = (target: InitializationTarget) => void;\r\n\r\nexport type UseOverlayScrollbarsInstance = () => ReturnType<\r\n OverlayScrollbarsComponentRef['osInstance']\r\n>;\r\n\r\nconst createDefer = (): Defer => {\r\n /* c8 ignore start */\r\n if (typeof window === 'undefined') {\r\n // mock ssr calls with \"noop\"\r\n // eslint-disable-next-line @typescript-eslint/no-empty-function\r\n const noop = () => {};\r\n return [noop, noop];\r\n }\r\n /* c8 ignore end */\r\n\r\n let idleId: number;\r\n let rafId: number;\r\n const wnd = window;\r\n const idleSupported = typeof wnd.requestIdleCallback === 'function';\r\n const rAF = wnd.requestAnimationFrame;\r\n const cAF = wnd.cancelAnimationFrame;\r\n const rIdle = idleSupported ? wnd.requestIdleCallback : rAF;\r\n const cIdle = idleSupported ? wnd.cancelIdleCallback : cAF;\r\n const clear = () => {\r\n cIdle(idleId);\r\n cAF(rafId);\r\n };\r\n\r\n return [\r\n (callback, options) => {\r\n clear();\r\n idleId = rIdle(\r\n idleSupported\r\n ? () => {\r\n clear();\r\n // inside idle its best practice to use rAF to change DOM for best performance\r\n rafId = rAF(callback);\r\n }\r\n : callback,\r\n typeof options === 'object' ? options : { timeout: 2233 }\r\n );\r\n },\r\n clear,\r\n ];\r\n};\r\n\r\n/**\r\n * Hook for advanced usage of OverlayScrollbars. (When the OverlayScrollbarsComponent is not enough)\r\n * @param params Parameters for customization.\r\n * @returns A tuple with two values:\r\n * The first value is the initialization function, it takes one argument which is the `InitializationTarget`.\r\n * The second value is a function which returns the current OverlayScrollbars instance or `null` if not initialized.\r\n */\r\nexport const useOverlayScrollbars = (\r\n params?: UseOverlayScrollbarsParams\r\n): [UseOverlayScrollbarsInitialization, UseOverlayScrollbarsInstance] => {\r\n const { options, events, defer } = params || {};\r\n const [requestDefer, cancelDefer] = useMemo<Defer>(createDefer, []);\r\n const instanceRef = useRef<ReturnType<UseOverlayScrollbarsInstance>>(null);\r\n const deferRef = useRef(defer);\r\n const optionsRef = useRef(options);\r\n const eventsRef = useRef(events);\r\n\r\n useEffect(() => {\r\n deferRef.current = defer;\r\n }, [defer]);\r\n\r\n useEffect(() => {\r\n const { current: instance } = instanceRef;\r\n\r\n optionsRef.current = options;\r\n\r\n if (OverlayScrollbars.valid(instance)) {\r\n instance.options(options || {}, true);\r\n }\r\n }, [options]);\r\n\r\n useEffect(() => {\r\n const { current: instance } = instanceRef;\r\n\r\n eventsRef.current = events;\r\n\r\n if (OverlayScrollbars.valid(instance)) {\r\n instance.on(events || {}, true);\r\n }\r\n }, [events]);\r\n\r\n useEffect(\r\n () => () => {\r\n cancelDefer();\r\n instanceRef.current?.destroy();\r\n },\r\n []\r\n );\r\n\r\n return useMemo<[UseOverlayScrollbarsInitialization, UseOverlayScrollbarsInstance]>(\r\n () => [\r\n (target) => {\r\n // if already initialized do nothing\r\n const presentInstance = instanceRef.current;\r\n if (OverlayScrollbars.valid(presentInstance)) {\r\n return;\r\n }\r\n\r\n const currDefer = deferRef.current;\r\n const currOptions = optionsRef.current || {};\r\n const currEvents = eventsRef.current || {};\r\n const init = () =>\r\n (instanceRef.current = OverlayScrollbars(target, currOptions, currEvents));\r\n\r\n if (currDefer) {\r\n requestDefer(init, currDefer);\r\n } else {\r\n init();\r\n }\r\n },\r\n () => instanceRef.current,\r\n ],\r\n []\r\n );\r\n};\r\n","import { forwardRef, useEffect, useRef, useImperativeHandle } from 'react';\r\nimport type { OverlayScrollbars } from 'overlayscrollbars';\r\nimport type { PartialOptions, EventListeners } from 'overlayscrollbars';\r\nimport type { ComponentPropsWithoutRef, ElementRef, ForwardedRef } from 'react';\r\nimport { useOverlayScrollbars } from './useOverlayScrollbars';\r\n\r\nexport type OverlayScrollbarsComponentProps<T extends keyof JSX.IntrinsicElements = 'div'> =\r\n ComponentPropsWithoutRef<T> & {\r\n /** Tag of the root element. */\r\n element?: T;\r\n /** OverlayScrollbars options. */\r\n options?: PartialOptions | false | null;\r\n /** OverlayScrollbars events. */\r\n events?: EventListeners | false | null;\r\n /** Whether to defer the initialization to a point in time when the browser is idle. (or to the next frame if `window.requestIdleCallback` is not supported) */\r\n defer?: boolean | IdleRequestOptions;\r\n };\r\n\r\nexport interface OverlayScrollbarsComponentRef<T extends keyof JSX.IntrinsicElements = 'div'> {\r\n /** Returns the OverlayScrollbars instance or null if not initialized. */\r\n osInstance(): OverlayScrollbars | null;\r\n /** Returns the root element. */\r\n getElement(): ElementRef<T> | null;\r\n}\r\n\r\nconst OverlayScrollbarsComponent = <T extends keyof JSX.IntrinsicElements>(\r\n props: OverlayScrollbarsComponentProps<T>,\r\n ref: ForwardedRef<OverlayScrollbarsComponentRef<T>>\r\n) => {\r\n const { element = 'div', options, events, defer, children, ...other } = props;\r\n const Tag = element;\r\n const elementRef = useRef<ElementRef<T>>(null);\r\n const childrenRef = useRef<HTMLDivElement>(null);\r\n const [initialize, osInstance] = useOverlayScrollbars({ options, events, defer });\r\n\r\n useEffect(() => {\r\n const { current: elm } = elementRef;\r\n const { current: childrenElm } = childrenRef;\r\n if (elm && childrenElm) {\r\n initialize({\r\n target: elm as any,\r\n elements: {\r\n viewport: childrenElm,\r\n content: childrenElm,\r\n },\r\n });\r\n }\r\n return () => osInstance()?.destroy();\r\n }, [initialize, element]);\r\n\r\n useImperativeHandle(\r\n ref,\r\n () => {\r\n return {\r\n osInstance,\r\n getElement: () => elementRef.current,\r\n };\r\n },\r\n []\r\n );\r\n\r\n return (\r\n // @ts-ignore\r\n <Tag data-overlayscrollbars-initialize=\"\" ref={elementRef} {...other}>\r\n <div ref={childrenRef}>{children}</div>\r\n </Tag>\r\n );\r\n};\r\n\r\nconst OverlayScrollbarsComponentForwardedRef = forwardRef(OverlayScrollbarsComponent) as <\r\n T extends keyof JSX.IntrinsicElements\r\n>(\r\n props: OverlayScrollbarsComponentProps<T> & {\r\n ref?: ForwardedRef<OverlayScrollbarsComponentRef<T>>;\r\n }\r\n) => ReturnType<typeof OverlayScrollbarsComponent>;\r\n\r\nexport { OverlayScrollbarsComponentForwardedRef as OverlayScrollbarsComponent };\r\n"],"names":["createDefer","noop","idleId","rafId","wnd","idleSupported","rAF","cAF","rIdle","cIdle","clear","callback","options","useOverlayScrollbars","params","events","defer","requestDefer","cancelDefer","useMemo","instanceRef","useRef","deferRef","optionsRef","eventsRef","useEffect","instance","OverlayScrollbars","_a","target","presentInstance","currDefer","currOptions","currEvents","init","OverlayScrollbarsComponent","props","ref","element","children","other","Tag","elementRef","childrenRef","initialize","osInstance","elm","childrenElm","useImperativeHandle","React","OverlayScrollbarsComponentForwardedRef","forwardRef"],"mappings":";;AA4BA,MAAMA,IAAc,MAAa;AAE3B,MAAA,OAAO,SAAW,KAAa;AAGjC,UAAMC,IAAO,MAAM;AAAA,IAAA;AACZ,WAAA,CAACA,GAAMA,CAAI;AAAA,EACpB;AAGI,MAAAC,GACAC;AACJ,QAAMC,IAAM,QACNC,IAAgB,OAAOD,EAAI,uBAAwB,YACnDE,IAAMF,EAAI,uBACVG,IAAMH,EAAI,sBACVI,IAAQH,IAAgBD,EAAI,sBAAsBE,GAClDG,IAAQJ,IAAgBD,EAAI,qBAAqBG,GACjDG,IAAQ,MAAM;AAClB,IAAAD,EAAMP,CAAM,GACZK,EAAIJ,CAAK;AAAA,EAAA;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,GAAcJ,CAAS,CACnC;AAEJ,GAEMW,IAAyCC,EAAWhB,CAA0B;"}
@@ -0,0 +1,2 @@
1
+ (function(c,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react"),require("overlayscrollbars")):typeof define=="function"&&define.amd?define(["exports","react","overlayscrollbars"],e):(c=typeof globalThis<"u"?globalThis:c||self,e(c.OverlayScrollbarsReact={},c.React,c.OverlayScrollbarsGlobal))})(this,function(c,e,y){"use strict";const O=(n=>n&&typeof n=="object"&&"default"in n?n:{default:n})(e),I=()=>{if(typeof window>"u"){const o=()=>{};return[o,o]}let n,l;const r=window,u=typeof r.requestIdleCallback=="function",i=r.requestAnimationFrame,a=r.cancelAnimationFrame,s=u?r.requestIdleCallback:i,d=u?r.cancelIdleCallback:a,f=()=>{d(n),a(l)};return[(o,t)=>{f(),n=s(u?()=>{f(),l=i(o)}:o,typeof t=="object"?t:{timeout:2233})},f]},E=n=>{const{options:l,events:r,defer:u}=n||{},[i,a]=e.useMemo(I,[]),s=e.useRef(null),d=e.useRef(u),f=e.useRef(l),o=e.useRef(r);return e.useEffect(()=>{d.current=u},[u]),e.useEffect(()=>{const{current:t}=s;f.current=l,y.OverlayScrollbars.valid(t)&&t.options(l||{},!0)},[l]),e.useEffect(()=>{const{current:t}=s;o.current=r,y.OverlayScrollbars.valid(t)&&t.on(r||{},!0)},[r]),e.useEffect(()=>()=>{var t;a(),(t=s.current)==null||t.destroy()},[]),e.useMemo(()=>[t=>{const b=s.current;if(y.OverlayScrollbars.valid(b))return;const p=d.current,S=f.current||{},v=o.current||{},m=()=>s.current=y.OverlayScrollbars(t,S,v);p?i(m,p):m()},()=>s.current],[])},w=(n,l)=>{const{element:r="div",options:u,events:i,defer:a,children:s,...d}=n,f=r,o=e.useRef(null),t=e.useRef(null),[b,p]=E({options:u,events:i,defer:a});return e.useEffect(()=>{const{current:S}=o,{current:v}=t;return S&&v&&b({target:S,elements:{viewport:v,content:v}}),()=>{var m;return(m=p())==null?void 0:m.destroy()}},[b,r]),e.useImperativeHandle(l,()=>({osInstance:p,getElement:()=>o.current}),[]),O.default.createElement(f,{"data-overlayscrollbars-initialize":"",ref:o,...d},O.default.createElement("div",{ref:t},s))},h=e.forwardRef(w);c.OverlayScrollbarsComponent=h,c.useOverlayScrollbars=E,Object.defineProperties(c,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
2
+ //# sourceMappingURL=overlayscrollbars-react.umd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"overlayscrollbars-react.umd.js","sources":["../src/useOverlayScrollbars.ts","../src/OverlayScrollbarsComponent.tsx"],"sourcesContent":["import { useEffect, useMemo, useRef } from 'react';\r\nimport { OverlayScrollbars } from 'overlayscrollbars';\r\nimport type { InitializationTarget } from 'overlayscrollbars';\r\nimport type {\r\n OverlayScrollbarsComponentProps,\r\n OverlayScrollbarsComponentRef,\r\n} from './OverlayScrollbarsComponent';\r\n\r\ntype Defer = [\r\n requestDefer: (callback: () => any, options?: OverlayScrollbarsComponentProps['defer']) => void,\r\n cancelDefer: () => void\r\n];\r\n\r\nexport interface UseOverlayScrollbarsParams {\r\n /** OverlayScrollbars options. */\r\n options?: OverlayScrollbarsComponentProps['options'];\r\n /** OverlayScrollbars events. */\r\n events?: OverlayScrollbarsComponentProps['events'];\r\n /** Whether to defer the initialization to a point in time when the browser is idle. (or to the next frame if `window.requestIdleCallback` is not supported) */\r\n defer?: OverlayScrollbarsComponentProps['defer'];\r\n}\r\n\r\nexport type UseOverlayScrollbarsInitialization = (target: InitializationTarget) => void;\r\n\r\nexport type UseOverlayScrollbarsInstance = () => ReturnType<\r\n OverlayScrollbarsComponentRef['osInstance']\r\n>;\r\n\r\nconst createDefer = (): Defer => {\r\n /* c8 ignore start */\r\n if (typeof window === 'undefined') {\r\n // mock ssr calls with \"noop\"\r\n // eslint-disable-next-line @typescript-eslint/no-empty-function\r\n const noop = () => {};\r\n return [noop, noop];\r\n }\r\n /* c8 ignore end */\r\n\r\n let idleId: number;\r\n let rafId: number;\r\n const wnd = window;\r\n const idleSupported = typeof wnd.requestIdleCallback === 'function';\r\n const rAF = wnd.requestAnimationFrame;\r\n const cAF = wnd.cancelAnimationFrame;\r\n const rIdle = idleSupported ? wnd.requestIdleCallback : rAF;\r\n const cIdle = idleSupported ? wnd.cancelIdleCallback : cAF;\r\n const clear = () => {\r\n cIdle(idleId);\r\n cAF(rafId);\r\n };\r\n\r\n return [\r\n (callback, options) => {\r\n clear();\r\n idleId = rIdle(\r\n idleSupported\r\n ? () => {\r\n clear();\r\n // inside idle its best practice to use rAF to change DOM for best performance\r\n rafId = rAF(callback);\r\n }\r\n : callback,\r\n typeof options === 'object' ? options : { timeout: 2233 }\r\n );\r\n },\r\n clear,\r\n ];\r\n};\r\n\r\n/**\r\n * Hook for advanced usage of OverlayScrollbars. (When the OverlayScrollbarsComponent is not enough)\r\n * @param params Parameters for customization.\r\n * @returns A tuple with two values:\r\n * The first value is the initialization function, it takes one argument which is the `InitializationTarget`.\r\n * The second value is a function which returns the current OverlayScrollbars instance or `null` if not initialized.\r\n */\r\nexport const useOverlayScrollbars = (\r\n params?: UseOverlayScrollbarsParams\r\n): [UseOverlayScrollbarsInitialization, UseOverlayScrollbarsInstance] => {\r\n const { options, events, defer } = params || {};\r\n const [requestDefer, cancelDefer] = useMemo<Defer>(createDefer, []);\r\n const instanceRef = useRef<ReturnType<UseOverlayScrollbarsInstance>>(null);\r\n const deferRef = useRef(defer);\r\n const optionsRef = useRef(options);\r\n const eventsRef = useRef(events);\r\n\r\n useEffect(() => {\r\n deferRef.current = defer;\r\n }, [defer]);\r\n\r\n useEffect(() => {\r\n const { current: instance } = instanceRef;\r\n\r\n optionsRef.current = options;\r\n\r\n if (OverlayScrollbars.valid(instance)) {\r\n instance.options(options || {}, true);\r\n }\r\n }, [options]);\r\n\r\n useEffect(() => {\r\n const { current: instance } = instanceRef;\r\n\r\n eventsRef.current = events;\r\n\r\n if (OverlayScrollbars.valid(instance)) {\r\n instance.on(events || {}, true);\r\n }\r\n }, [events]);\r\n\r\n useEffect(\r\n () => () => {\r\n cancelDefer();\r\n instanceRef.current?.destroy();\r\n },\r\n []\r\n );\r\n\r\n return useMemo<[UseOverlayScrollbarsInitialization, UseOverlayScrollbarsInstance]>(\r\n () => [\r\n (target) => {\r\n // if already initialized do nothing\r\n const presentInstance = instanceRef.current;\r\n if (OverlayScrollbars.valid(presentInstance)) {\r\n return;\r\n }\r\n\r\n const currDefer = deferRef.current;\r\n const currOptions = optionsRef.current || {};\r\n const currEvents = eventsRef.current || {};\r\n const init = () =>\r\n (instanceRef.current = OverlayScrollbars(target, currOptions, currEvents));\r\n\r\n if (currDefer) {\r\n requestDefer(init, currDefer);\r\n } else {\r\n init();\r\n }\r\n },\r\n () => instanceRef.current,\r\n ],\r\n []\r\n );\r\n};\r\n","import { forwardRef, useEffect, useRef, useImperativeHandle } from 'react';\r\nimport type { OverlayScrollbars } from 'overlayscrollbars';\r\nimport type { PartialOptions, EventListeners } from 'overlayscrollbars';\r\nimport type { ComponentPropsWithoutRef, ElementRef, ForwardedRef } from 'react';\r\nimport { useOverlayScrollbars } from './useOverlayScrollbars';\r\n\r\nexport type OverlayScrollbarsComponentProps<T extends keyof JSX.IntrinsicElements = 'div'> =\r\n ComponentPropsWithoutRef<T> & {\r\n /** Tag of the root element. */\r\n element?: T;\r\n /** OverlayScrollbars options. */\r\n options?: PartialOptions | false | null;\r\n /** OverlayScrollbars events. */\r\n events?: EventListeners | false | null;\r\n /** Whether to defer the initialization to a point in time when the browser is idle. (or to the next frame if `window.requestIdleCallback` is not supported) */\r\n defer?: boolean | IdleRequestOptions;\r\n };\r\n\r\nexport interface OverlayScrollbarsComponentRef<T extends keyof JSX.IntrinsicElements = 'div'> {\r\n /** Returns the OverlayScrollbars instance or null if not initialized. */\r\n osInstance(): OverlayScrollbars | null;\r\n /** Returns the root element. */\r\n getElement(): ElementRef<T> | null;\r\n}\r\n\r\nconst OverlayScrollbarsComponent = <T extends keyof JSX.IntrinsicElements>(\r\n props: OverlayScrollbarsComponentProps<T>,\r\n ref: ForwardedRef<OverlayScrollbarsComponentRef<T>>\r\n) => {\r\n const { element = 'div', options, events, defer, children, ...other } = props;\r\n const Tag = element;\r\n const elementRef = useRef<ElementRef<T>>(null);\r\n const childrenRef = useRef<HTMLDivElement>(null);\r\n const [initialize, osInstance] = useOverlayScrollbars({ options, events, defer });\r\n\r\n useEffect(() => {\r\n const { current: elm } = elementRef;\r\n const { current: childrenElm } = childrenRef;\r\n if (elm && childrenElm) {\r\n initialize({\r\n target: elm as any,\r\n elements: {\r\n viewport: childrenElm,\r\n content: childrenElm,\r\n },\r\n });\r\n }\r\n return () => osInstance()?.destroy();\r\n }, [initialize, element]);\r\n\r\n useImperativeHandle(\r\n ref,\r\n () => {\r\n return {\r\n osInstance,\r\n getElement: () => elementRef.current,\r\n };\r\n },\r\n []\r\n );\r\n\r\n return (\r\n // @ts-ignore\r\n <Tag data-overlayscrollbars-initialize=\"\" ref={elementRef} {...other}>\r\n <div ref={childrenRef}>{children}</div>\r\n </Tag>\r\n );\r\n};\r\n\r\nconst OverlayScrollbarsComponentForwardedRef = forwardRef(OverlayScrollbarsComponent) as <\r\n T extends keyof JSX.IntrinsicElements\r\n>(\r\n props: OverlayScrollbarsComponentProps<T> & {\r\n ref?: ForwardedRef<OverlayScrollbarsComponentRef<T>>;\r\n }\r\n) => ReturnType<typeof OverlayScrollbarsComponent>;\r\n\r\nexport { OverlayScrollbarsComponentForwardedRef as OverlayScrollbarsComponent };\r\n"],"names":["createDefer","noop","idleId","rafId","wnd","idleSupported","rAF","cAF","rIdle","cIdle","clear","callback","options","useOverlayScrollbars","params","events","defer","requestDefer","cancelDefer","useMemo","instanceRef","useRef","deferRef","optionsRef","eventsRef","useEffect","instance","OverlayScrollbars","_a","target","presentInstance","currDefer","currOptions","currEvents","init","OverlayScrollbarsComponent","props","ref","element","children","other","Tag","elementRef","childrenRef","initialize","osInstance","elm","childrenElm","useImperativeHandle","React","OverlayScrollbarsCompon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EACA,WAAY,IAAMH,EAAW,OAAA,GAGjC,CAAC,CAAA,EAKAO,EAAA,QAAA,cAAAR,EAAA,CAAI,oCAAkC,GAAG,IAAKC,EAAa,GAAGF,CAAA,EAC5DS,EAAA,QAAA,cAAA,MAAA,CAAI,IAAKN,CAAA,EAAcJ,CAAS,CACnC,CAEJ,EAEMW,EAAyCC,aAAWhB,CAA0B"}
package/package.json CHANGED
@@ -1,52 +1,33 @@
1
1
  {
2
- "name": "overlayscrollbars-react",
3
- "version": "0.3.0",
4
- "description": "OverlayScrollbars wrapper for React.",
5
- "keywords": [
6
- "overlayscrollbars",
7
- "react"
8
- ],
9
- "files": [
10
- "src",
11
- "dist"
12
- ],
13
- "homepage": "https://kingsora.github.io/OverlayScrollbars",
14
- "repository": {
15
- "type": "git",
16
- "url": "https://github.com/KingSora/OverlayScrollbars"
17
- },
18
- "bugs": {
19
- "url": "https://github.com/KingSora/OverlayScrollbars/issues"
20
- },
21
- "main": "./dist/overlayscrollbars-react.js",
22
- "module": "./dist/overlayscrollbars-react.esm.js",
23
- "typings": "./dist/types/index.d.ts",
24
- "author": "KingSora | Rene Haas",
25
- "license": "MIT",
26
- "devDependencies": {
27
- "@types/overlayscrollbars": "^1.9.0",
28
- "@types/react": "^18.0.0",
29
- "chalk": "^2.4.2",
30
- "gulp": "^4.0.2",
31
- "gulp-json-editor": "^2.5.4",
32
- "overlayscrollbars": "^1.11.0",
33
- "react": "^18.0.0",
34
- "rollup": "^1.32.1",
35
- "rollup-plugin-commonjs": "^10.1.0",
36
- "rollup-plugin-node-resolve": "^5.2.0",
37
- "rollup-plugin-typescript2": "^0.22.0",
38
- "shelljs": "^0.8.3",
39
- "typescript": "^3.8.3"
40
- },
41
- "peerDependencies": {
42
- "react": "^16.4.0 || ^17.0.0 || ^18.0.0",
43
- "overlayscrollbars": "^1.10.0"
44
- },
45
- "scripts": {
46
- "setup": "npm i && cd example && npm i && cd ..",
47
- "build": "node build.js",
48
- "example": "cd example && npm start",
49
- "build-example": "cd example && npm run build",
50
- "test": "echo \"Error: no test specified\" && exit 1"
51
- }
2
+ "name": "overlayscrollbars-react",
3
+ "version": "0.5.0",
4
+ "description": "OverlayScrollbars for React.",
5
+ "author": "Rene Haas | KingSora",
6
+ "license": "MIT",
7
+ "homepage": "https://kingsora.github.io/OverlayScrollbars",
8
+ "bugs": "https://github.com/KingSora/OverlayScrollbars/issues",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/KingSora/OverlayScrollbars.git",
12
+ "directory": "packages/overlayscrollbars-react"
13
+ },
14
+ "keywords": [
15
+ "overlayscrollbars",
16
+ "react",
17
+ "component",
18
+ "hook",
19
+ "hooks",
20
+ "styleable",
21
+ "scrollbar",
22
+ "scrollbars",
23
+ "scroll"
24
+ ],
25
+ "main": "overlayscrollbars-react.umd.js",
26
+ "module": "overlayscrollbars-react.es.js",
27
+ "types": "types/overlayscrollbars-react.d.ts",
28
+ "peerDependencies": {
29
+ "react": ">=16.8.0",
30
+ "overlayscrollbars": "^2.0.0"
31
+ },
32
+ "sideEffects": false
52
33
  }
@@ -0,0 +1,60 @@
1
+ import type { OverlayScrollbars } from 'overlayscrollbars';
2
+ import type { PartialOptions, EventListeners } from 'overlayscrollbars';
3
+ import type { ComponentPropsWithoutRef, ElementRef, ForwardedRef } from 'react';
4
+ export declare type OverlayScrollbarsComponentProps<T extends keyof JSX.IntrinsicElements = 'div'> = ComponentPropsWithoutRef<T> & {
5
+ /** Tag of the root element. */
6
+ element?: T;
7
+ /** OverlayScrollbars options. */
8
+ options?: PartialOptions | false | null;
9
+ /** OverlayScrollbars events. */
10
+ events?: EventListeners | false | null;
11
+ /** Whether to defer the initialization to a point in time when the browser is idle. (or to the next frame if `window.requestIdleCallback` is not supported) */
12
+ defer?: boolean | IdleRequestOptions;
13
+ };
14
+ export interface OverlayScrollbarsComponentRef<T extends keyof JSX.IntrinsicElements = 'div'> {
15
+ /** Returns the OverlayScrollbars instance or null if not initialized. */
16
+ osInstance(): OverlayScrollbars | null;
17
+ /** Returns the root element. */
18
+ getElement(): ElementRef<T> | null;
19
+ }
20
+ declare const OverlayScrollbarsComponent: <T extends keyof JSX.IntrinsicElements>(props: OverlayScrollbarsComponentProps<T>, ref: ForwardedRef<OverlayScrollbarsComponentRef<T>>) => JSX.Element;
21
+ declare const OverlayScrollbarsComponentForwardedRef: <T extends keyof JSX.IntrinsicElements>(props: import("react").PropsWithoutRef<import("react").ComponentProps<T>> & {
22
+ /** Tag of the root element. */
23
+ element?: T | undefined;
24
+ /** OverlayScrollbars options. */
25
+ options?: false | {
26
+ paddingAbsolute?: boolean | undefined;
27
+ showNativeOverlaidScrollbars?: boolean | undefined;
28
+ update?: {
29
+ elementEvents?: [elementSelector: string, eventNames: string][] | null | undefined;
30
+ debounce?: number | [timeout: number, maxWait: number] | null | undefined;
31
+ attributes?: string[] | null | undefined;
32
+ ignoreMutation?: ((mutation: MutationRecord) => any) | null | undefined;
33
+ } | undefined;
34
+ overflow?: {
35
+ x?: import("overlayscrollbars").OverflowBehavior | undefined;
36
+ y?: import("overlayscrollbars").OverflowBehavior | undefined;
37
+ } | undefined;
38
+ scrollbars?: {
39
+ theme?: string | null | undefined;
40
+ visibility?: import("overlayscrollbars").ScrollbarsVisibilityBehavior | undefined;
41
+ autoHide?: import("overlayscrollbars").ScrollbarsAutoHideBehavior | undefined;
42
+ autoHideDelay?: number | undefined;
43
+ dragScroll?: boolean | undefined;
44
+ clickScroll?: boolean | undefined;
45
+ pointers?: string[] | null | undefined;
46
+ } | undefined;
47
+ } | null | undefined;
48
+ /** OverlayScrollbars events. */
49
+ events?: false | {
50
+ initialized?: ((instance: OverlayScrollbars) => void) | ((instance: OverlayScrollbars) => void)[] | null | undefined;
51
+ updated?: ((instance: OverlayScrollbars, onUpdatedArgs: import("overlayscrollbars").OnUpdatedEventListenerArgs) => void) | ((instance: OverlayScrollbars, onUpdatedArgs: import("overlayscrollbars").OnUpdatedEventListenerArgs) => void)[] | null | undefined;
52
+ destroyed?: ((instance: OverlayScrollbars, canceled: boolean) => void) | ((instance: OverlayScrollbars, canceled: boolean) => void)[] | null | undefined;
53
+ scroll?: ((instance: OverlayScrollbars, event: Event) => void) | ((instance: OverlayScrollbars, event: Event) => void)[] | null | undefined;
54
+ } | null | undefined;
55
+ /** Whether to defer the initialization to a point in time when the browser is idle. (or to the next frame if `window.requestIdleCallback` is not supported) */
56
+ defer?: boolean | IdleRequestOptions | undefined;
57
+ } & {
58
+ ref?: ForwardedRef<OverlayScrollbarsComponentRef<T>> | undefined;
59
+ }) => ReturnType<typeof OverlayScrollbarsComponent>;
60
+ export { OverlayScrollbarsComponentForwardedRef as OverlayScrollbarsComponent };
@@ -1 +1,2 @@
1
1
  export * from './OverlayScrollbarsComponent';
2
+ export * from './useOverlayScrollbars';
@@ -0,0 +1,20 @@
1
+ import type { InitializationTarget } from 'overlayscrollbars';
2
+ import type { OverlayScrollbarsComponentProps, OverlayScrollbarsComponentRef } from './OverlayScrollbarsComponent';
3
+ export interface UseOverlayScrollbarsParams {
4
+ /** OverlayScrollbars options. */
5
+ options?: OverlayScrollbarsComponentProps['options'];
6
+ /** OverlayScrollbars events. */
7
+ events?: OverlayScrollbarsComponentProps['events'];
8
+ /** Whether to defer the initialization to a point in time when the browser is idle. (or to the next frame if `window.requestIdleCallback` is not supported) */
9
+ defer?: OverlayScrollbarsComponentProps['defer'];
10
+ }
11
+ export declare type UseOverlayScrollbarsInitialization = (target: InitializationTarget) => void;
12
+ export declare type UseOverlayScrollbarsInstance = () => ReturnType<OverlayScrollbarsComponentRef['osInstance']>;
13
+ /**
14
+ * Hook for advanced usage of OverlayScrollbars. (When the OverlayScrollbarsComponent is not enough)
15
+ * @param params Parameters for customization.
16
+ * @returns A tuple with two values:
17
+ * The first value is the initialization function, it takes one argument which is the `InitializationTarget`.
18
+ * The second value is a function which returns the current OverlayScrollbars instance or `null` if not initialized.
19
+ */
20
+ export declare const useOverlayScrollbars: (params?: UseOverlayScrollbarsParams) => [UseOverlayScrollbarsInitialization, UseOverlayScrollbarsInstance];
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2019 Rene Haas
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,89 +0,0 @@
1
- import React, { Component } from 'react';
2
- import OverlayScrollbars from 'overlayscrollbars';
3
-
4
- /*! *****************************************************************************
5
- Copyright (c) Microsoft Corporation. All rights reserved.
6
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
7
- this file except in compliance with the License. You may obtain a copy of the
8
- License at http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
12
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
13
- MERCHANTABLITY OR NON-INFRINGEMENT.
14
-
15
- See the Apache Version 2.0 License for specific language governing permissions
16
- and limitations under the License.
17
- ***************************************************************************** */
18
-
19
- function __rest(s, e) {
20
- var t = {};
21
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
22
- t[p] = s[p];
23
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
24
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
25
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
26
- t[p[i]] = s[p[i]];
27
- }
28
- return t;
29
- }
30
-
31
- class OverlayScrollbarsComponent extends Component {
32
- constructor(props) {
33
- super(props);
34
- this._osInstance = null;
35
- this._osTargetRef = React.createRef();
36
- }
37
- osInstance() {
38
- return this._osInstance;
39
- }
40
- osTarget() {
41
- return this._osTargetRef.current || null;
42
- }
43
- componentDidMount() {
44
- this._osInstance = OverlayScrollbars(this.osTarget(), this.props.options || {}, this.props.extensions);
45
- mergeHostClassNames(this._osInstance, this.props.className);
46
- }
47
- componentWillUnmount() {
48
- if (OverlayScrollbars.valid(this._osInstance)) {
49
- this._osInstance.destroy();
50
- this._osInstance = null;
51
- }
52
- }
53
- componentDidUpdate(prevProps) {
54
- if (OverlayScrollbars.valid(this._osInstance)) {
55
- this._osInstance.options(this.props.options);
56
- if (prevProps.className !== this.props.className) {
57
- mergeHostClassNames(this._osInstance, this.props.className);
58
- }
59
- }
60
- }
61
- render() {
62
- const _a = this.props, divProps = __rest(_a, ["options", "extensions", "children", "className"]);
63
- return (React.createElement("div", Object.assign({ className: "os-host" }, divProps, { ref: this._osTargetRef }),
64
- React.createElement("div", { className: "os-resize-observer-host" }),
65
- React.createElement("div", { className: "os-padding" },
66
- React.createElement("div", { className: "os-viewport" },
67
- React.createElement("div", { className: "os-content" }, this.props.children))),
68
- React.createElement("div", { className: "os-scrollbar os-scrollbar-horizontal " },
69
- React.createElement("div", { className: "os-scrollbar-track" },
70
- React.createElement("div", { className: "os-scrollbar-handle" }))),
71
- React.createElement("div", { className: "os-scrollbar os-scrollbar-vertical" },
72
- React.createElement("div", { className: "os-scrollbar-track" },
73
- React.createElement("div", { className: "os-scrollbar-handle" }))),
74
- React.createElement("div", { className: "os-scrollbar-corner" })));
75
- }
76
- }
77
- function mergeHostClassNames(osInstance, className) {
78
- if (OverlayScrollbars.valid(osInstance)) {
79
- const { host } = osInstance.getElements();
80
- const regex = new RegExp(`(^os-host([-_].+|)$)|${osInstance.options().className.replace(/\s/g, "$|")}$`, 'g');
81
- const osClassNames = host.className.split(' ')
82
- .filter(name => name.match(regex))
83
- .join(' ');
84
- host.className = `${osClassNames} ${className || ''}`;
85
- }
86
- }
87
-
88
- export { OverlayScrollbarsComponent };
89
- //# sourceMappingURL=overlayscrollbars-react.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"overlayscrollbars-react.esm.js","sources":["../src/OverlayScrollbarsComponent.tsx"],"sourcesContent":["import React, { Component, RefObject } from 'react';\r\nimport OverlayScrollbars from \"overlayscrollbars\";\r\n\r\nexport interface OverlayScrollbarsComponentProps extends React.HTMLAttributes<HTMLDivElement> {\r\n children?: any;\r\n options?: OverlayScrollbars.Options;\r\n extensions?: OverlayScrollbars.Extensions;\r\n}\r\nexport interface OverlayScrollbarsComponentState { }\r\n\r\nexport class OverlayScrollbarsComponent extends Component<OverlayScrollbarsComponentProps, OverlayScrollbarsComponentState> {\r\n private _osInstance: OverlayScrollbars | null = null;\r\n private _osTargetRef: RefObject<HTMLDivElement>;\r\n\r\n constructor(props: OverlayScrollbarsComponentProps) {\r\n super(props);\r\n this._osTargetRef = React.createRef();\r\n }\r\n\r\n osInstance(): OverlayScrollbars | null {\r\n return this._osInstance;\r\n }\r\n\r\n osTarget(): HTMLDivElement | null {\r\n return this._osTargetRef.current || null;\r\n }\r\n\r\n componentDidMount() {\r\n this._osInstance = OverlayScrollbars(this.osTarget(), this.props.options || {}, this.props.extensions);\r\n mergeHostClassNames(this._osInstance, this.props.className);\r\n }\r\n\r\n componentWillUnmount() {\r\n if (OverlayScrollbars.valid(this._osInstance)) {\r\n this._osInstance.destroy();\r\n this._osInstance = null;\r\n }\r\n }\r\n\r\n componentDidUpdate(prevProps: OverlayScrollbarsComponentProps) {\r\n if (OverlayScrollbars.valid(this._osInstance)) {\r\n this._osInstance.options(this.props.options);\r\n\r\n if (prevProps.className !== this.props.className) {\r\n mergeHostClassNames(this._osInstance, this.props.className);\r\n }\r\n }\r\n }\r\n\r\n render() {\r\n const {\r\n options,\r\n extensions,\r\n children,\r\n className,\r\n ...divProps\r\n } = this.props;\r\n\r\n return (\r\n <div className=\"os-host\" {...divProps} ref={this._osTargetRef}>\r\n <div className=\"os-resize-observer-host\"></div>\r\n <div className=\"os-padding\">\r\n <div className=\"os-viewport\">\r\n <div className=\"os-content\">\r\n {this.props.children}\r\n </div>\r\n </div>\r\n </div>\r\n <div className=\"os-scrollbar os-scrollbar-horizontal \">\r\n <div className=\"os-scrollbar-track\">\r\n <div className=\"os-scrollbar-handle\"></div>\r\n </div>\r\n </div>\r\n <div className=\"os-scrollbar os-scrollbar-vertical\">\r\n <div className=\"os-scrollbar-track\">\r\n <div className=\"os-scrollbar-handle\"></div>\r\n </div>\r\n </div>\r\n <div className=\"os-scrollbar-corner\"></div>\r\n </div>\r\n );\r\n }\r\n}\r\n\r\nfunction mergeHostClassNames(osInstance: OverlayScrollbars, className: string) {\r\n if (OverlayScrollbars.valid(osInstance)) {\r\n const { host } = osInstance.getElements();\r\n const regex = new RegExp(`(^os-host([-_].+|)$)|${osInstance.options().className.replace(/\\s/g, \"$|\")}$`, 'g');\r\n const osClassNames = host.className.split(' ')\r\n .filter(name => name.match(regex))\r\n .join(' ');\r\n\r\n host.className = `${osClassNames} ${className || ''}`;\r\n }\r\n}"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAUa,0BAA2B,SAAQ,SAA2E;IAIvH,YAAY,KAAsC;QAC9C,KAAK,CAAC,KAAK,CAAC,CAAC;QAJT,gBAAW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;gBACvB,6BAAK,SAAS,EAAC,aAAa;oBACxB,6BAAK,SAAS,EAAC,YAAY,IACtB,IAAI,CAAC,KAAK,CAAC,QAAQ,CAClB,CACJ,CACJ;YACN,6BAAK,SAAS,EAAC,uCAAuC;gBAClD,6BAAK,SAAS,EAAC,oBAAoB;oBAC/B,6BAAK,SAAS,EAAC,qBAAqB,GAAO,CACzC,CACJ;YACN,6BAAK,SAAS,EAAC,oCAAoC;gBAC/C,6BAAK,SAAS,EAAC,oBAAoB;oBAC/B,6BAAK,SAAS,EAAC,qBAAqB,GAAO,CACzC,CACJ;YACN,6BAAK,SAAS,EAAC,qBAAqB,GAAO,CACzC,EACR;KACL;CACJ;AAED,SAAS,mBAAmB,CAAC,UAA6B,EAAE,SAAiB;IACzE,IAAI,iBAAiB,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE;QACrC,MAAM,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC;QAC1C,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,wBAAwB,UAAU,CAAC,OAAO,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAC9G,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC;aACzC,MAAM,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;aACjC,IAAI,CAAC,GAAG,CAAC,CAAC;QAEf,IAAI,CAAC,SAAS,GAAG,GAAG,YAAY,IAAI,SAAS,IAAI,EAAE,EAAE,CAAC;KACzD;AACL;;;;"}
@@ -1,127 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('overlayscrollbars')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'react', 'overlayscrollbars'], factory) :
4
- (global = global || self, factory(global.OverlayScrollbarsReact = {}, global.React, global.OverlayScrollbars));
5
- }(this, (function (exports, React, OverlayScrollbars) { 'use strict';
6
-
7
- var React__default = 'default' in React ? React['default'] : React;
8
- OverlayScrollbars = OverlayScrollbars && Object.prototype.hasOwnProperty.call(OverlayScrollbars, 'default') ? OverlayScrollbars['default'] : OverlayScrollbars;
9
-
10
- /*! *****************************************************************************
11
- Copyright (c) Microsoft Corporation. All rights reserved.
12
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
13
- this file except in compliance with the License. You may obtain a copy of the
14
- License at http://www.apache.org/licenses/LICENSE-2.0
15
-
16
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
18
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
19
- MERCHANTABLITY OR NON-INFRINGEMENT.
20
-
21
- See the Apache Version 2.0 License for specific language governing permissions
22
- and limitations under the License.
23
- ***************************************************************************** */
24
- /* global Reflect, Promise */
25
-
26
- var extendStatics = function(d, b) {
27
- extendStatics = Object.setPrototypeOf ||
28
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
29
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
30
- return extendStatics(d, b);
31
- };
32
-
33
- function __extends(d, b) {
34
- extendStatics(d, b);
35
- function __() { this.constructor = d; }
36
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
37
- }
38
-
39
- var __assign = function() {
40
- __assign = Object.assign || function __assign(t) {
41
- for (var s, i = 1, n = arguments.length; i < n; i++) {
42
- s = arguments[i];
43
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
44
- }
45
- return t;
46
- };
47
- return __assign.apply(this, arguments);
48
- };
49
-
50
- function __rest(s, e) {
51
- var t = {};
52
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
53
- t[p] = s[p];
54
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
55
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
56
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
57
- t[p[i]] = s[p[i]];
58
- }
59
- return t;
60
- }
61
-
62
- var OverlayScrollbarsComponent = (function (_super) {
63
- __extends(OverlayScrollbarsComponent, _super);
64
- function OverlayScrollbarsComponent(props) {
65
- var _this = _super.call(this, props) || this;
66
- _this._osInstance = null;
67
- _this._osTargetRef = React__default.createRef();
68
- return _this;
69
- }
70
- OverlayScrollbarsComponent.prototype.osInstance = function () {
71
- return this._osInstance;
72
- };
73
- OverlayScrollbarsComponent.prototype.osTarget = function () {
74
- return this._osTargetRef.current || null;
75
- };
76
- OverlayScrollbarsComponent.prototype.componentDidMount = function () {
77
- this._osInstance = OverlayScrollbars(this.osTarget(), this.props.options || {}, this.props.extensions);
78
- mergeHostClassNames(this._osInstance, this.props.className);
79
- };
80
- OverlayScrollbarsComponent.prototype.componentWillUnmount = function () {
81
- if (OverlayScrollbars.valid(this._osInstance)) {
82
- this._osInstance.destroy();
83
- this._osInstance = null;
84
- }
85
- };
86
- OverlayScrollbarsComponent.prototype.componentDidUpdate = function (prevProps) {
87
- if (OverlayScrollbars.valid(this._osInstance)) {
88
- this._osInstance.options(this.props.options);
89
- if (prevProps.className !== this.props.className) {
90
- mergeHostClassNames(this._osInstance, this.props.className);
91
- }
92
- }
93
- };
94
- OverlayScrollbarsComponent.prototype.render = function () {
95
- var _a = this.props, options = _a.options, extensions = _a.extensions, children = _a.children, className = _a.className, divProps = __rest(_a, ["options", "extensions", "children", "className"]);
96
- return (React__default.createElement("div", __assign({ className: "os-host" }, divProps, { ref: this._osTargetRef }),
97
- React__default.createElement("div", { className: "os-resize-observer-host" }),
98
- React__default.createElement("div", { className: "os-padding" },
99
- React__default.createElement("div", { className: "os-viewport" },
100
- React__default.createElement("div", { className: "os-content" }, this.props.children))),
101
- React__default.createElement("div", { className: "os-scrollbar os-scrollbar-horizontal " },
102
- React__default.createElement("div", { className: "os-scrollbar-track" },
103
- React__default.createElement("div", { className: "os-scrollbar-handle" }))),
104
- React__default.createElement("div", { className: "os-scrollbar os-scrollbar-vertical" },
105
- React__default.createElement("div", { className: "os-scrollbar-track" },
106
- React__default.createElement("div", { className: "os-scrollbar-handle" }))),
107
- React__default.createElement("div", { className: "os-scrollbar-corner" })));
108
- };
109
- return OverlayScrollbarsComponent;
110
- }(React.Component));
111
- function mergeHostClassNames(osInstance, className) {
112
- if (OverlayScrollbars.valid(osInstance)) {
113
- var host = osInstance.getElements().host;
114
- var regex_1 = new RegExp("(^os-host([-_].+|)$)|" + osInstance.options().className.replace(/\s/g, "$|") + "$", 'g');
115
- var osClassNames = host.className.split(' ')
116
- .filter(function (name) { return name.match(regex_1); })
117
- .join(' ');
118
- host.className = osClassNames + " " + (className || '');
119
- }
120
- }
121
-
122
- exports.OverlayScrollbarsComponent = OverlayScrollbarsComponent;
123
-
124
- Object.defineProperty(exports, '__esModule', { value: true });
125
-
126
- })));
127
- //# sourceMappingURL=overlayscrollbars-react.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"overlayscrollbars-react.js","sources":["../src/OverlayScrollbarsComponent.tsx"],"sourcesContent":["import React, { Component, RefObject } from 'react';\r\nimport OverlayScrollbars from \"overlayscrollbars\";\r\n\r\nexport interface OverlayScrollbarsComponentProps extends React.HTMLAttributes<HTMLDivElement> {\r\n children?: any;\r\n options?: OverlayScrollbars.Options;\r\n extensions?: OverlayScrollbars.Extensions;\r\n}\r\nexport interface OverlayScrollbarsComponentState { }\r\n\r\nexport class OverlayScrollbarsComponent extends Component<OverlayScrollbarsComponentProps, OverlayScrollbarsComponentState> {\r\n private _osInstance: OverlayScrollbars | null = null;\r\n private _osTargetRef: RefObject<HTMLDivElement>;\r\n\r\n constructor(props: OverlayScrollbarsComponentProps) {\r\n super(props);\r\n this._osTargetRef = React.createRef();\r\n }\r\n\r\n osInstance(): OverlayScrollbars | null {\r\n return this._osInstance;\r\n }\r\n\r\n osTarget(): HTMLDivElement | null {\r\n return this._osTargetRef.current || null;\r\n }\r\n\r\n componentDidMount() {\r\n this._osInstance = OverlayScrollbars(this.osTarget(), this.props.options || {}, this.props.extensions);\r\n mergeHostClassNames(this._osInstance, this.props.className);\r\n }\r\n\r\n componentWillUnmount() {\r\n if (OverlayScrollbars.valid(this._osInstance)) {\r\n this._osInstance.destroy();\r\n this._osInstance = null;\r\n }\r\n }\r\n\r\n componentDidUpdate(prevProps: OverlayScrollbarsComponentProps) {\r\n if (OverlayScrollbars.valid(this._osInstance)) {\r\n this._osInstance.options(this.props.options);\r\n\r\n if (prevProps.className !== this.props.className) {\r\n mergeHostClassNames(this._osInstance, this.props.className);\r\n }\r\n }\r\n }\r\n\r\n render() {\r\n const {\r\n options,\r\n extensions,\r\n children,\r\n className,\r\n ...divProps\r\n } = this.props;\r\n\r\n return (\r\n <div className=\"os-host\" {...divProps} ref={this._osTargetRef}>\r\n <div className=\"os-resize-observer-host\"></div>\r\n <div className=\"os-padding\">\r\n <div className=\"os-viewport\">\r\n <div className=\"os-content\">\r\n {this.props.children}\r\n </div>\r\n </div>\r\n </div>\r\n <div className=\"os-scrollbar os-scrollbar-horizontal \">\r\n <div className=\"os-scrollbar-track\">\r\n <div className=\"os-scrollbar-handle\"></div>\r\n </div>\r\n </div>\r\n <div className=\"os-scrollbar os-scrollbar-vertical\">\r\n <div className=\"os-scrollbar-track\">\r\n <div className=\"os-scrollbar-handle\"></div>\r\n </div>\r\n </div>\r\n <div className=\"os-scrollbar-corner\"></div>\r\n </div>\r\n );\r\n }\r\n}\r\n\r\nfunction mergeHostClassNames(osInstance: OverlayScrollbars, className: string) {\r\n if (OverlayScrollbars.valid(osInstance)) {\r\n const { host } = osInstance.getElements();\r\n const regex = new RegExp(`(^os-host([-_].+|)$)|${osInstance.options().className.replace(/\\s/g, \"$|\")}$`, 'g');\r\n const osClassNames = host.className.split(' ')\r\n .filter(name => name.match(regex))\r\n .join(' ');\r\n\r\n host.className = `${osClassNames} ${className || ''}`;\r\n }\r\n}"],"names":["React","Component"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAUgD,8CAA2E;QAIvH,oCAAY,KAAsC;YAAlD,YACI,kBAAM,KAAK,CAAC,SAEf;YANO,iBAAW,GAA6B,IAAI,CAAC;YAKjD,KAAI,CAAC,YAAY,GAAGA,cAAK,CAAC,SAAS,EAAE,CAAC;;SACzC;QAED,+CAAU,GAAV;YACI,OAAO,IAAI,CAAC,WAAW,CAAC;SAC3B;QAED,6CAAQ,GAAR;YACI,OAAO,IAAI,CAAC,YAAY,CAAC,OAAO,IAAI,IAAI,CAAC;SAC5C;QAED,sDAAiB,GAAjB;YACI,IAAI,CAAC,WAAW,GAAG,iBAAiB,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,IAAI,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;YACvG,mBAAmB,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;SAC/D;QAED,yDAAoB,GAApB;YACI,IAAI,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE;gBAC3C,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;gBAC3B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;aAC3B;SACJ;QAED,uDAAkB,GAAlB,UAAmB,SAA0C;YACzD,IAAI,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE;gBAC3C,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;gBAE7C,IAAI,SAAS,CAAC,SAAS,KAAK,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AAK,CAAC,GAAG,CAAC;iBACzC,MAAM,CAAC,UAAA,IAAI,IAAI,OAAA,IAAI,CAAC,KAAK,CAAC,OAAK,CAAC,GAAA,CAAC;iBACjC,IAAI,CAAC,GAAG,CAAC,CAAC;YAEf,IAAI,CAAC,SAAS,GAAM,YAAY,UAAI,SAAS,IAAI,EAAE,CAAE,CAAC;SACzD;IACL;;;;;;;;;;;;"}
@@ -1,20 +0,0 @@
1
- import React, { Component } from 'react';
2
- import OverlayScrollbars from "overlayscrollbars";
3
- export interface OverlayScrollbarsComponentProps extends React.HTMLAttributes<HTMLDivElement> {
4
- children?: any;
5
- options?: OverlayScrollbars.Options;
6
- extensions?: OverlayScrollbars.Extensions;
7
- }
8
- export interface OverlayScrollbarsComponentState {
9
- }
10
- export declare class OverlayScrollbarsComponent extends Component<OverlayScrollbarsComponentProps, OverlayScrollbarsComponentState> {
11
- private _osInstance;
12
- private _osTargetRef;
13
- constructor(props: OverlayScrollbarsComponentProps);
14
- osInstance(): OverlayScrollbars | null;
15
- osTarget(): HTMLDivElement | null;
16
- componentDidMount(): void;
17
- componentWillUnmount(): void;
18
- componentDidUpdate(prevProps: OverlayScrollbarsComponentProps): void;
19
- render(): JSX.Element;
20
- }
@@ -1,95 +0,0 @@
1
- import React, { Component, RefObject } from 'react';
2
- import OverlayScrollbars from "overlayscrollbars";
3
-
4
- export interface OverlayScrollbarsComponentProps extends React.HTMLAttributes<HTMLDivElement> {
5
- children?: any;
6
- options?: OverlayScrollbars.Options;
7
- extensions?: OverlayScrollbars.Extensions;
8
- }
9
- export interface OverlayScrollbarsComponentState { }
10
-
11
- export class OverlayScrollbarsComponent extends Component<OverlayScrollbarsComponentProps, OverlayScrollbarsComponentState> {
12
- private _osInstance: OverlayScrollbars | null = null;
13
- private _osTargetRef: RefObject<HTMLDivElement>;
14
-
15
- constructor(props: OverlayScrollbarsComponentProps) {
16
- super(props);
17
- this._osTargetRef = React.createRef();
18
- }
19
-
20
- osInstance(): OverlayScrollbars | null {
21
- return this._osInstance;
22
- }
23
-
24
- osTarget(): HTMLDivElement | null {
25
- return this._osTargetRef.current || null;
26
- }
27
-
28
- componentDidMount() {
29
- this._osInstance = OverlayScrollbars(this.osTarget(), this.props.options || {}, this.props.extensions);
30
- mergeHostClassNames(this._osInstance, this.props.className);
31
- }
32
-
33
- componentWillUnmount() {
34
- if (OverlayScrollbars.valid(this._osInstance)) {
35
- this._osInstance.destroy();
36
- this._osInstance = null;
37
- }
38
- }
39
-
40
- componentDidUpdate(prevProps: OverlayScrollbarsComponentProps) {
41
- if (OverlayScrollbars.valid(this._osInstance)) {
42
- this._osInstance.options(this.props.options);
43
-
44
- if (prevProps.className !== this.props.className) {
45
- mergeHostClassNames(this._osInstance, this.props.className);
46
- }
47
- }
48
- }
49
-
50
- render() {
51
- const {
52
- options,
53
- extensions,
54
- children,
55
- className,
56
- ...divProps
57
- } = this.props;
58
-
59
- return (
60
- <div className="os-host" {...divProps} ref={this._osTargetRef}>
61
- <div className="os-resize-observer-host"></div>
62
- <div className="os-padding">
63
- <div className="os-viewport">
64
- <div className="os-content">
65
- {this.props.children}
66
- </div>
67
- </div>
68
- </div>
69
- <div className="os-scrollbar os-scrollbar-horizontal ">
70
- <div className="os-scrollbar-track">
71
- <div className="os-scrollbar-handle"></div>
72
- </div>
73
- </div>
74
- <div className="os-scrollbar os-scrollbar-vertical">
75
- <div className="os-scrollbar-track">
76
- <div className="os-scrollbar-handle"></div>
77
- </div>
78
- </div>
79
- <div className="os-scrollbar-corner"></div>
80
- </div>
81
- );
82
- }
83
- }
84
-
85
- function mergeHostClassNames(osInstance: OverlayScrollbars, className: string) {
86
- if (OverlayScrollbars.valid(osInstance)) {
87
- const { host } = osInstance.getElements();
88
- const regex = new RegExp(`(^os-host([-_].+|)$)|${osInstance.options().className.replace(/\s/g, "$|")}$`, 'g');
89
- const osClassNames = host.className.split(' ')
90
- .filter(name => name.match(regex))
91
- .join(' ');
92
-
93
- host.className = `${osClassNames} ${className || ''}`;
94
- }
95
- }
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './OverlayScrollbarsComponent';