2.2.1 • Published 3 months ago

ngx-cut v2.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

npm version Package License NPM Downloads Build & Publish Snyk codecov stars forks HitCount

Angular directive for cutting texts with responsive options

Angular 17 compatible

Here's the demo or stackblitz live preview or codesandbox live preview

  • Lightweight
  • No dependencies!
  • Directive way
  • Highly customizable options...
  • Responsivity supported
  • Predefined breakpoints (Bootrstrap, CDK, FxLayout, Tailwind)

Install

  1. Use yarn (or npm) to install the package
yarn add ngx-cut
  1. Add NgxCutModule into your imports
  export const appConfig: ApplicationConfig = {
    providers: [
      importProvidersFrom(
        BrowserModule,
        NgxCutModule.forRoot({
          size: 1,
          breakpoints: { sm: 300, md: 400, lg: 500, xl: 600 },
          responsiveSizes: {
            xs: { xs: 1, sm: 2, md: 3, lg: 4, xl: 5 },
            sm: { xs: 2, sm: 3, md: 4, lg: 5, xl: 6 },
            md: { xs: 3, sm: 4, md: 5, lg: 6, xl: 7 },
            lg: { xs: 4, sm: 5, md: 6, lg: 7, xl: 8 },
            xl: { xs: 5, sm: 6, md: 7, lg: 8, xl: 9 }
          }
        })
      )
    ]
  };

  // or

  import { NgxCutModule } from 'ngx-cut';

  @NgModule({
   // ...
   imports: [
     // ...
     NgxCutModule.forRoot({
       // directive without [size] uses this value
       size: 1,
       // custom breakpoints
       breakpoints: { sm: 300, md: 400, lg: 500, xl: 600 },
       // lines be truncated in responsive mode
       responsiveSizes: {
         xs: { xs: 1, sm: 2, md: 3, lg: 4, xl: 5 },
         sm: { xs: 2, sm: 3, md: 4, lg: 5, xl: 6 },
         md: { xs: 3, sm: 4, md: 5, lg: 6, xl: 7 },
         lg: { xs: 4, sm: 5, md: 6, lg: 7, xl: 8 },
         xl: { xs: 5, sm: 6, md: 7, lg: 8, xl: 9 }
       }
     })
   ]
  })

  // or

  @NgModule({
   // ...
   imports: [
     // ...
     NgxCutModule.forRoot({
       // directive without [size] uses responsiveSizes.sm
       size: 'sm',
       // predefined breakpoint ('BOOTSTRAP', 'FX_LAYOUT' or 'CDK')
       breakpoints: 'BOOTSTRAP',
       // lines be truncated in responsive mode
       responsiveSizes: {
         xs: { xs: 1, sm: 2, md: 3, lg: 4, xl: 5 },
         sm: { xs: 2, sm: 3, md: 4, lg: 5, xl: 6 },
         md: { xs: 3, sm: 4, md: 5, lg: 6, xl: 7 },
         lg: { xs: 4, sm: 5, md: 6, lg: 7, xl: 8 },
         xl: { xs: 5, sm: 6, md: 7, lg: 8, xl: 9 }
       }
     })
   ]
  })

  // or

  @NgModule({
   // ...
   imports: [
     // ...
     NgxCutModule
   ]
  })

Compatibility

Angularngx-cutInstall
>= 122.xyarn add ngx-cut
>= 5 < 131.xyarn add ngx-cut@1
>= 5 < 130.xyarn add ngx-cut@0

Quick start

Example code

<p ngxCut>some long text</p>

Result

  some long...

Options

Root options

OptionTypeDefaultDescription
sizestring or number1Number of truncated lines
breakpointsobjectDEFAULT_BREAKPOINTSBreakpoints used in responsive mode
responsiveSizesobjectDEFAULT_RESPONSIVE_SIZESHow many lines should be truncated for each breakpoint

Directive

OptionTypeDefaultDescription
sizeobjectvalue taken from root optionsNumber of truncated lines or responsive mode
truncateDisabledbooleanfalseWhether truncation is active or not
(truncateChange)() => objectnoneEvent called when truncation is changed.

Dependencies

None

License

Copyright © 2020 - 2024 Dominik Hladik

All contents are licensed under the MIT license.

2.2.1

3 months ago

2.2.0

4 months ago

2.1.0

9 months ago

2.0.5

1 year ago

2.0.3

1 year ago

2.0.4

1 year ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.1.0

3 years ago

1.0.29

3 years ago

1.0.30

3 years ago

1.0.28

3 years ago

1.0.27

3 years ago

1.0.26

3 years ago

1.0.25

3 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.22

3 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.12

4 years ago

1.0.13

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.1

4 years ago

0.0.0

4 years ago