Skip to content

Commit

Permalink
feat(web): added breakpointChrome and breakpointTailwindCSS (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
pikax committed Feb 8, 2020
1 parent 7fb7d05 commit 923e7de
Show file tree
Hide file tree
Showing 18 changed files with 492 additions and 102 deletions.
16 changes: 12 additions & 4 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,24 @@ module.exports = {
["composable/date/performanceNow", "performanceNow"]
]
},

{
title: "Misc",
title: "Breakpoint",
sidebarDepth: 1,
collapsable: false,
children: [
["composable/misc/matchMedia", "matchMedia"],
["composable/misc/breakpoint", "breakpoint"],
["composable/misc/sharedRef", "SharedRef"]
["composable/breakpoint/matchMedia", "matchMedia"],
["composable/breakpoint/breakpoint", "breakpoint"],
["composable/breakpoint/breakpointChrome", "Chrome"],
["composable/breakpoint/breakpointTailwindCSS", "TailwindCSS"]
]
},
{
title: "Misc",
sidebarDepth: 1,
collapsable: false,
children: [["composable/misc/sharedRef", "SharedRef"]]
},
{
title: "Storage",
sidebarDepth: 1,
Expand Down
11 changes: 7 additions & 4 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,15 @@ Check out the [examples folder](examples) or start hacking on [codesandbox](http
- [Resize](composable/event/onResize) - Attach `resize` listener to a DOM element
- [Scroll](composable/event/onScroll) - Attach `scroll` listener to a DOM element

### Breakpoint

- [MatchMedia](composable/breakpoint/matchMedia) - reactive `MatchMedia`
- [Breakpoint](composable/breakpoint/breakpoint) - reactive `breakpoints` based on `window.innerWidth`
- [Chrome](composable/breakpoint/breakpointChrome) - reactive chrome breakpoints
- [TailwindCSS](composable/breakpoint/breakpointTailwindCSS) - reactive TailwindCSS breakpoints

### MISC

- [MatchMedia](composable/misc/matchMedia) - reactive `MatchMedia`
- [Breakpoint](composable/misc/breakpoint) - reactive `breakpoints` based on `window.innerWidth`
- [sharedRef](composable/misc/sharedRef) - cross-tab reactive `ref`

### Storage
Expand Down Expand Up @@ -133,6 +138,4 @@ export default {

### Pagination example


<array-pagination-example/>

59 changes: 55 additions & 4 deletions docs/api/web.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,43 @@ import { Ref } from '@vue/composition-api';
import { RefElement } from '@vue-composable/core';
import { RefTyped } from '@vue-composable/core';

// @public (undocumented)
export type BreakpointObject = Record<string, string | number>;

// @public (undocumented)
export type BreakpointReturn<T> = Record<keyof T, Ref<boolean>> & BreakpointReturnObject<T>;

// @public (undocumented)
export interface BreakpointReturnObject<T> {
// (undocumented)
current: Ref<keyof T | undefined>;
// (undocumented)
remove: RemoveEventFunction;
}

// @public (undocumented)
export interface BroadcastMessageEvent<T> extends MessageEvent {
// (undocumented)
readonly data: T;
}

// @public (undocumented)
export interface DefaultTailwindBreakpoints {
// (undocumented)
lg: 1024;
// (undocumented)
md: 768;
// (undocumented)
sm: 640;
// (undocumented)
xl: 1280;
}

// Warning: (ae-forgotten-export) The symbol "TailwindConfigEmpty" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export type ExtractTailwindScreens<T extends TailwindConfigEmpty> = keyof T["theme"]["screens"] extends never ? DefaultTailwindBreakpoints : T["theme"]["screens"];

// @public (undocumented)
export interface GeolocationOptions {
immediate?: boolean;
Expand Down Expand Up @@ -194,6 +225,12 @@ export interface ScrollResult {
scrollTop: Ref<number>;
}

// @public (undocumented)
export function setBreakpointTailwindCSS<T extends TailwindConfigEmpty>(tailwindConfig: T): BreakpointReturn<ExtractTailwindScreens<T>>;

// @public (undocumented)
export function setBreakpointTailwindCSS<T extends BreakpointObject>(breakpoints: T): BreakpointReturn<T>;

// @public (undocumented)
export const enum SharedRefMind {
// (undocumented)
Expand All @@ -214,10 +251,24 @@ export interface StorageSerializer<T = any> {
}

// @public (undocumented)
export function useBreakpoint<T>(breakpoints: Record<keyof T, number | string>): Record<keyof T, Ref<boolean>> & {
remove: RemoveEventFunction;
current: Ref<keyof T | undefined>;
};
export function useBreakpoint<T extends BreakpointObject>(breakpoints: Record<keyof T, number | string>): BreakpointReturn<T>;

// Warning: (ae-forgotten-export) The symbol "ChromeBreakpoint" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export function useBreakpointChrome(): BreakpointReturn<ChromeBreakpoint>;

// @public (undocumented)
export function useBreakpointTailwindCSS<T extends TailwindConfigEmpty>(tailwindConfig: T): BreakpointReturn<ExtractTailwindScreens<T>>;

// @public (undocumented)
export function useBreakpointTailwindCSS<T extends TailwindConfigEmpty>(): BreakpointReturn<ExtractTailwindScreens<T>>;

// @public (undocumented)
export function useBreakpointTailwindCSS(): BreakpointReturn<DefaultTailwindBreakpoints>;

// @public (undocumented)
export function useBreakpointTailwindCSS<T extends BreakpointObject>(): BreakpointReturn<T>;

// @public (undocumented)
export function useBroadcastChannel<T = any>(name: string, onBeforeClose?: Function): {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
Allows to get reactive object on the current windows size.

::: warning
If `Number` it checks the defined breakpoint against window.innerWidth.
If `Number` or `{Number}px` it checks the defined breakpoint against window.innerWidth.
`bp >= window.innerWidth`
If `MediaQuery` is passed it will not be able to resolve the current breakpoint
If `MediaQuery` is passed it will not be able to resolve the `current` breakpoint
:::

## State
Expand Down Expand Up @@ -43,10 +43,8 @@ const { remove } = useBreakpoint();

## Example


<breakpoint-example/>


### Code

```vue
Expand Down
25 changes: 25 additions & 0 deletions docs/composable/breakpoint/breakpointChrome.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Chrome breakpoints

> Use the Chrome breakpoints within javascript code.
## Usage

Check [useBreakpoint](./breakpoint.md) for more detailed usage

```js
import { useBreakpointChrome } from "vue-composable";

useBreakpointChrome();
/* Equivalent of:
useBreakpoint({
mobileS: 320,
mobileM: 375,
mobileL: 425,
tablet: 768,
laptop: 1024,
laptopL: 1440,
desktop4K: 2560
})
*/
```
102 changes: 102 additions & 0 deletions docs/composable/breakpoint/breakpointTailwindCSS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# TailwindCSS breakpoints

> Use the TailwindCSS breakpoints within javascript code.
## Parameters

```js
import { useBreakpointTailwindCSS } from "vue-composable";

useBreakpointTailwindCSS(tailwindConfig?);
```
| Parameters | Type | Required | Default | Description |
| -------------- | -------------------- | -------- | ----------- | --------------------------- |
| tailwindConfig | `tailwind.config.js` | `false` | `undefined` | `tailwind.config.js` object |
## Usage
Check [useBreakpoint](./breakpoint.md) for more detailed usage
### Default
```js
import { useBreakpointTailwindCSS } from "vue-composable";

/**
* it uses the default config found :
* https://github.com/tailwindcss/tailwindcss/blob/master/stubs/defaultConfig.stub.js
**/
useBreakpointTailwindCSS();
```
### With custom `tailwind.config.js`
```js
// tailwind.config.js
module.exports = {
theme: {
screens: {
mobileS: "320px",
mobileM: "375px",
mobileL: "425px",
tablet: "768px",
laptop: "1024px",
laptopL: "1440px"
}
},
variants: {
/* custom variants */
},
plugins: [
/* custom plugins */
]
};

// usage
import { useBreakpointTailwindCSS } from "vue-composable";
import tailwindConfig from "@/tailwind.config.js"; // location may be different

useBreakpointTailwindCSS(tailwindConfig);
/* Equivalent as:
useBreakpoint({
mobileS: 320,
mobileM: 375,
mobileL: 425,
tablet: 768,
laptop: 1024,
laptopL: 1440
})
*/
```
### Usage with `inject/provide` with `typescript`
```ts
// parent.component.vue

import {
ExtractTailwindScreens,
useBreakpointTailwindCSS
} from "vue-composable";
import tailwindConfig from "@/tailwind.config.js"; // location may be different

export type TailwindConfigType = typeof tailwindConfig;

setup(){
setBreakpointTailwindCSS(tailwindConfig); // provide config
// ...
}

// child.component.vue

import { TailwindConfigType } from 'parent.component.vue' // you should move this type to an other file

setup(){
useBreakpointTailwindCSS<TailwindConfigType>() // retrieve breakpoints
// ...
}

```
File renamed without changes.
9 changes: 7 additions & 2 deletions packages/vue-composable/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,15 @@ Check our [documentation](https://pikax.me/vue-composable/)
- [useDateNow][date-now] : Returns reactive `Date.now()` with custom refresh rate
- [usePerformanceNow][performance-now] : Returns reactive `performance.now()` with custom refresh rate

### Breakpoint

- [MatchMedia](https://pikax.me/vue-composable/composable/breakpoint/matchMedia) - reactive `MatchMedia`
- [Breakpoint](https://pikax.me/vue-composable/composable/breakpoint/breakpoint) - reactive `breakpoints` based on `window.innerWidth`
- [Chrome](https://pikax.me/vue-composable/composable/breakpoint/breakpointChrome) - reactive chrome breakpoints
- [TailwindCSS](https://pikax.me/vue-composable/composable/breakpoint/breakpointTailwindCSS) - reactive TailwindCSS breakpoints

### MISC

- [matchMedia](https://pikax.me/vue-composable/composable/misc/matchMedia) - Reactive `matchMedia`
- [breakpoint](https://pikax.me/vue-composable/composable/misc/breakpoint) - reactive `breakpoints` based on `window.innerWidth`
- [sharedRef](https://pikax.me/vue-composable/composable/misc/sharedRef) - cross-tab reactive `ref`

### Storage
Expand Down
9 changes: 7 additions & 2 deletions packages/web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ Check our [documentation](https://pikax.me/vue-composable/)
- [Resize](https://pikax.me/vue-composable/composable/event/onResize) - Attach `resize` listener to a DOM element
- [Scroll](https://pikax.me/vue-composable/composable/event/onScroll) - Attach `scroll` listener to a DOM element

### Breakpoint

- [MatchMedia](https://pikax.me/vue-composable/composable/breakpoint/matchMedia) - reactive `MatchMedia`
- [Breakpoint](https://pikax.me/vue-composable/composable/breakpoint/breakpoint) - reactive `breakpoints` based on `window.innerWidth`
- [Chrome](https://pikax.me/vue-composable/composable/breakpoint/breakpointChrome) - reactive chrome breakpoints
- [TailwindCSS](https://pikax.me/vue-composable/composable/breakpoint/breakpointTailwindCSS) - reactive TailwindCSS breakpoints

### MISC

- [matchMedia](https://pikax.me/vue-composable/composable/misc/matchMedia) - Reactive `matchMedia`
- [breakpoint](https://pikax.me/vue-composable/composable/misc/breakpoint) - reactive `breakpoints` based on `window.innerWidth`
- [sharedRef](https://pikax.me/vue-composable/composable/misc/sharedRef) - cross-tab reactive `ref`

### Storage
Expand Down

0 comments on commit 923e7de

Please sign in to comment.