From 245fe7b5e6771ac36a676d37c41767b2ce3b8d72 Mon Sep 17 00:00:00 2001 From: splincode Date: Mon, 5 Aug 2024 14:02:40 +0300 Subject: [PATCH] feat(core): add `mode` for `tui-scrollbar` --- projects/core/components/scrollbar/index.ts | 1 + .../scrollbar/scrollbar.component.ts | 3 ++ .../components/scrollbar/scrollbar.options.ts | 22 ++++++++ .../components/scrollbar/scrollbar.style.less | 12 +++++ .../scrollbar/scrollbar.template.html | 1 + .../scrollbar/examples/7/index.html | 50 +++++++++++++++++++ .../scrollbar/examples/7/index.less | 13 +++++ .../components/scrollbar/examples/7/index.ts | 18 +++++++ .../scrollbar/scrollbar.component.ts | 6 +++ .../components/scrollbar/scrollbar.module.ts | 2 + .../scrollbar/scrollbar.template.html | 8 +++ 11 files changed, 136 insertions(+) create mode 100644 projects/core/components/scrollbar/scrollbar.options.ts create mode 100644 projects/demo/src/modules/components/scrollbar/examples/7/index.html create mode 100644 projects/demo/src/modules/components/scrollbar/examples/7/index.less create mode 100644 projects/demo/src/modules/components/scrollbar/examples/7/index.ts diff --git a/projects/core/components/scrollbar/index.ts b/projects/core/components/scrollbar/index.ts index 01466b797884..3a3dfa58596c 100644 --- a/projects/core/components/scrollbar/index.ts +++ b/projects/core/components/scrollbar/index.ts @@ -2,3 +2,4 @@ export * from './scroll-ref.directive'; export * from './scrollable.directive'; export * from './scrollbar.component'; export * from './scrollbar.module'; +export * from './scrollbar.options'; diff --git a/projects/core/components/scrollbar/scrollbar.component.ts b/projects/core/components/scrollbar/scrollbar.component.ts index d7f46cc22f6d..e6f97d89ff57 100644 --- a/projects/core/components/scrollbar/scrollbar.component.ts +++ b/projects/core/components/scrollbar/scrollbar.component.ts @@ -17,6 +17,8 @@ import { } from '@taiga-ui/cdk'; import {TUI_SCROLL_INTO_VIEW, TUI_SCROLLABLE} from '@taiga-ui/core/constants'; +import {TUI_SCROLLBAR_OPTIONS, TuiScrollbarOptions} from './scrollbar.options'; + // TODO: Remove all legacy code in 4.0 @Component({ selector: 'tui-scrollbar', @@ -50,6 +52,7 @@ export class TuiScrollbarComponent { @Inject(ElementRef) private readonly el: ElementRef, @Inject(USER_AGENT) private readonly userAgent: string, @Inject(TUI_IS_IOS) private readonly isIos: boolean, + @Inject(TUI_SCROLLBAR_OPTIONS) readonly options: TuiScrollbarOptions, ) {} get delegated(): boolean { diff --git a/projects/core/components/scrollbar/scrollbar.options.ts b/projects/core/components/scrollbar/scrollbar.options.ts new file mode 100644 index 000000000000..48a7d61d265b --- /dev/null +++ b/projects/core/components/scrollbar/scrollbar.options.ts @@ -0,0 +1,22 @@ +import type {Provider} from '@angular/core'; +import {tuiCreateToken, tuiProvideOptions} from '@taiga-ui/cdk'; + +export interface TuiScrollbarOptions { + mode: 'always' | 'hover'; +} + +export const TUI_DEFAULT_SCROLLBAR_OPTIONS: TuiScrollbarOptions = { + mode: 'always', +}; + +export const TUI_SCROLLBAR_OPTIONS = tuiCreateToken(TUI_DEFAULT_SCROLLBAR_OPTIONS); + +export function tuiScrollbarOptionsProvider( + options: Partial, +): Provider { + return tuiProvideOptions( + TUI_SCROLLBAR_OPTIONS, + options, + TUI_DEFAULT_SCROLLBAR_OPTIONS, + ); +} diff --git a/projects/core/components/scrollbar/scrollbar.style.less b/projects/core/components/scrollbar/scrollbar.style.less index 4eadd048a1d7..c2a085cba443 100644 --- a/projects/core/components/scrollbar/scrollbar.style.less +++ b/projects/core/components/scrollbar/scrollbar.style.less @@ -24,6 +24,18 @@ .customize-scroll(); overflow: overlay; } + + .t-hover-mode:not(:active) { + .transition(opacity); + + opacity: 0; + } + + &:hover .t-hover-mode { + .transition(opacity); + + opacity: 1; + } } .t-content { diff --git a/projects/core/components/scrollbar/scrollbar.template.html b/projects/core/components/scrollbar/scrollbar.template.html index 9f276ad5f6e0..0f55f36a61b6 100644 --- a/projects/core/components/scrollbar/scrollbar.template.html +++ b/projects/core/components/scrollbar/scrollbar.template.html @@ -1,6 +1,7 @@
+
+

+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. Deleniti dignissimos, doloremque. Aperiam + assumenda atque aut blanditiis corporis, eum, facilis harum laudantium magni necessitatibus nobis quas + repudiandae sint ut voluptatem! Optio. +

+

+ Accusamus aperiam assumenda aut consectetur, corporis delectus, dolor eaque eius est hic impedit labore + possimus provident quas rem, rerum sequi sint tempora tempore ut? Debitis esse neque odio odit provident? +

+

+ Cum eum illo, ipsa iure nostrum ut voluptates? Autem blanditiis corporis debitis deserunt ex expedita + facilis fuga, illum iusto magnam praesentium provident recusandae repudiandae, totam, voluptatem. Minima + numquam sapiente sunt. +

+

+ Beatae consectetur cupiditate dignissimos ducimus eos excepturi labore pariatur placeat quia similique. + Architecto aspernatur cumque debitis distinctio esse, facere fugit harum ipsum libero minus neque numquam + omnis quidem, tempora, ut! +

+

+ Mollitia, perspiciatis sunt! Architecto aspernatur assumenda beatae, blanditiis commodi consequuntur debitis + et id, laboriosam maxime molestiae neque nihil officiis omnis, quam quos sint veritatis voluptate? Alias + deserunt distinctio modi perferendis? +

+

+ Ab aspernatur aut cumque cupiditate deleniti, dolorem ducimus eligendi eos facere harum hic ipsam ipsum iste + itaque modi nam necessitatibus nostrum nulla omnis quae repellat, sapiente sit tempore. Ipsam, quidem! +

+

+ Ab debitis deleniti distinctio est ex facere magni nemo numquam placeat quia, quibusdam sequi! Aliquid at + consectetur culpa ea enim facilis, harum hic, inventore iste possimus praesentium quas tempora voluptates. +

+

+ Aliquam eligendi ipsam modi nemo numquam obcaecati officia, quidem unde? Accusantium amet, animi deleniti + dolorum ea earum eos, expedita ipsa minima modi, pariatur perspiciatis porro quibusdam quo repellat tempore + voluptates! +

+

+ Ab assumenda fugiat magni natus officiis perferendis ratione rem repellendus tenetur. At commodi laudantium + modi, natus nobis nulla odio odit sed sint tempora tenetur voluptas? At odio praesentium quas ut! +

+

+ Atque aut consectetur consequuntur debitis eius facere ipsa ipsam maiores minima minus mollitia qui quos + repudiandae sapiente, soluta? Ad, amet dolore doloribus ducimus eos exercitationem molestiae quisquam soluta + ullam voluptate. +

+
+ diff --git a/projects/demo/src/modules/components/scrollbar/examples/7/index.less b/projects/demo/src/modules/components/scrollbar/examples/7/index.less new file mode 100644 index 000000000000..93d36a68ab97 --- /dev/null +++ b/projects/demo/src/modules/components/scrollbar/examples/7/index.less @@ -0,0 +1,13 @@ +.box { + width: 16rem; + height: 16rem; + border: 1px solid; +} + +.content { + padding: 0 0.6875rem; +} + +p { + white-space: nowrap; +} diff --git a/projects/demo/src/modules/components/scrollbar/examples/7/index.ts b/projects/demo/src/modules/components/scrollbar/examples/7/index.ts new file mode 100644 index 000000000000..a1a647069d8e --- /dev/null +++ b/projects/demo/src/modules/components/scrollbar/examples/7/index.ts @@ -0,0 +1,18 @@ +import {Component} from '@angular/core'; +import {changeDetection} from '@demo/emulate/change-detection'; +import {encapsulation} from '@demo/emulate/encapsulation'; +import {tuiScrollbarOptionsProvider} from '@taiga-ui/core'; + +@Component({ + selector: 'tui-scrollbar-example-7', + templateUrl: './index.html', + styleUrls: ['./index.less'], + encapsulation, + changeDetection, + providers: [ + tuiScrollbarOptionsProvider({ + mode: 'hover', + }), + ], +}) +export class TuiScrollbarExample7Component {} diff --git a/projects/demo/src/modules/components/scrollbar/scrollbar.component.ts b/projects/demo/src/modules/components/scrollbar/scrollbar.component.ts index d73f143ba956..64a30d9c270d 100644 --- a/projects/demo/src/modules/components/scrollbar/scrollbar.component.ts +++ b/projects/demo/src/modules/components/scrollbar/scrollbar.component.ts @@ -44,4 +44,10 @@ export class ExampleTuiScrollbarComponent { HTML: import('./examples/6/template.html?raw'), LESS: import('./examples/6/style.less?raw'), }; + + readonly example7: TuiDocExample = { + TypeScript: import('./examples/7/index.ts?raw'), + HTML: import('./examples/7/index.html?raw'), + LESS: import('./examples/7/index.less?raw'), + }; } diff --git a/projects/demo/src/modules/components/scrollbar/scrollbar.module.ts b/projects/demo/src/modules/components/scrollbar/scrollbar.module.ts index 78aa9b6859e1..2dd42ec2a596 100644 --- a/projects/demo/src/modules/components/scrollbar/scrollbar.module.ts +++ b/projects/demo/src/modules/components/scrollbar/scrollbar.module.ts @@ -16,6 +16,7 @@ import {TuiScrollbarExample3Component} from './examples/3/component'; import {TuiScrollbarExample4Component} from './examples/4/component'; import {TuiScrollbarExample5Component} from './examples/5/component'; import {TuiScrollbarExample6Component} from './examples/6/component'; +import {TuiScrollbarExample7Component} from './examples/7'; import {ExampleTuiScrollbarComponent} from './scrollbar.component'; @NgModule({ @@ -37,6 +38,7 @@ import {ExampleTuiScrollbarComponent} from './scrollbar.component'; TuiScrollbarExample4Component, TuiScrollbarExample5Component, TuiScrollbarExample6Component, + TuiScrollbarExample7Component, ], exports: [ExampleTuiScrollbarComponent], }) diff --git a/projects/demo/src/modules/components/scrollbar/scrollbar.template.html b/projects/demo/src/modules/components/scrollbar/scrollbar.template.html index dc8fc25f08d7..8bc3ad910ef2 100644 --- a/projects/demo/src/modules/components/scrollbar/scrollbar.template.html +++ b/projects/demo/src/modules/components/scrollbar/scrollbar.template.html @@ -71,6 +71,14 @@

+ + + +