Skip to content

Commit

Permalink
feat: add isLessOrEquals function (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanXDR authored Oct 6, 2024
1 parent ed4d7b4 commit a521a3a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,16 @@ viewport.isLessThan('desktopWide') // Result: true.
viewport.isLessThan('mobile') // Result: false.
```

### `viewport.isLessOrEquals`
- Type: Boolean

```js
// Example: viewport.breakpoint is "tablet".

viewport.isLessOrEquals('tablet') // Result: true.
viewport.isLessOrEquals('mobile') // Result: false.
```

### `viewport.match`
- Type: Boolean

Expand Down
3 changes: 3 additions & 0 deletions playground/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<p>
<code>isLessThan</code> → <b>{{ $viewport.isLessThan(breakpoint) }}</b>
</p>
<p>
<code>isLessOrEquals</code> → <b>{{ $viewport.isLessOrEquals(breakpoint) }}</b>
</p>
<p>
<code>isGreaterThan</code> → <b>{{ $viewport.isGreaterThan(breakpoint) }}</b>
</p>
Expand Down
9 changes: 9 additions & 0 deletions src/runtime/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export function createViewportManager(options: ViewportOptions, state: Ref<strin
isGreaterOrEquals,

isLessThan,
isLessOrEquals,

match,
matches,
Expand Down Expand Up @@ -128,6 +129,14 @@ export function createViewportManager(options: ViewportOptions, state: Ref<strin
return breakpointIndex < currentIndex
}

/**
* Returns true, if searchBreakpoint is less or equals the current breakpoint.
* @param searchBreakpoint - Breakpoint to search.
*/
function isLessOrEquals(searchBreakpoint: string) {
return isLessThan(searchBreakpoint) || match(searchBreakpoint)
}

/**
* Returns true if current breakpoint is matching the value.
* @param breakpointToMatch - Breakpoint value to match.
Expand Down

0 comments on commit a521a3a

Please sign in to comment.