-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feature(modal): add drag to close functionality * feat(commitlint): add feat rule * fix: update lock file * refactor(modal): update drag constraints * feat(hooks): add custom breakpoint hooks * feat(hooks): add custom useIsMobile hook * refactor(modal): update content to only be draggable on mobile screens * style(modal): refactor styles * ci(changesets): add changeset for modal refactor * style(modal): adjust styles for better mobile response
- Loading branch information
1 parent
727c1f4
commit 6bda776
Showing
19 changed files
with
252 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@hobbescodes/tigris-ui": patch | ||
--- | ||
|
||
Update responsive design of `Modal` component |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
// inject root cascade layers | ||
import "lib/styles/main.css"; | ||
|
||
// export preset | ||
export { tigrisPreset } from "lib/theme/presets"; | ||
|
||
// 🐼 export backfill of Panda components | ||
export * from "generated/panda/css"; | ||
export * from "generated/panda/jsx"; | ||
export type { JsxStyleProps } from "generated/panda/types"; | ||
|
||
// export components | ||
export * from "components"; | ||
|
||
// export hooks | ||
export * from "lib/hooks"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { default as useBreakpoint } from "./useBreakpoint/useBreakpoint"; | ||
export { default as useBreakpointValue } from "./useBreakpointValue/useBreakpointValue"; | ||
export { default as useIsMobile } from "./useIsMobile/useIsMobile"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { useEffect, useState } from "react"; | ||
|
||
import { breakpoints } from "lib/theme/extensions/base"; | ||
import { emToPx } from "lib/util"; | ||
|
||
import type { BreakpointToken } from "generated/panda/tokens"; | ||
|
||
interface WindowDimensions { | ||
width: typeof window.innerWidth; | ||
height: typeof window.innerHeight; | ||
} | ||
|
||
export interface Options { | ||
/** Fallback breakpoint to use if no match is found, or if `window` is undefined as in server-side contexts. Defaults to "base". */ | ||
fallback?: BreakpointToken; | ||
} | ||
|
||
/** | ||
* Get the current theme breakpoint. | ||
*/ | ||
const useBreakpoint = ({ fallback = "base" }: Options = {}) => { | ||
const [breakpoint, setBreakpoint] = useState<BreakpointToken>(fallback), | ||
[windowDimensions, setWindowDimensions] = useState<WindowDimensions>({ | ||
width: 0, | ||
height: 0, | ||
}); | ||
|
||
const handleResize = () => { | ||
setWindowDimensions({ | ||
width: window.innerWidth, | ||
height: window.innerHeight, | ||
}); | ||
}; | ||
|
||
useEffect(() => { | ||
// attach listener to window `resize` event | ||
window.addEventListener("resize", handleResize); | ||
handleResize(); | ||
|
||
// create tuple mapping of semantic breakpoint keys with their values | ||
const range = Object.entries(breakpoints) | ||
.map(([key, breakpoint]) => [key, emToPx(breakpoint as `${number}em`)]) | ||
// reverse to set largest breakpoint at the start (top-down; decreasing order) | ||
.reverse(); | ||
|
||
setBreakpoint( | ||
// find the first "floored" breakpoint below the window width | ||
range.find( | ||
([, breakpoint]) => +breakpoint <= windowDimensions.width | ||
)?.[0] as BreakpointToken | ||
); | ||
|
||
// clean up listener | ||
return () => window.removeEventListener("resize", handleResize); | ||
}, [windowDimensions.width]); | ||
|
||
return breakpoint; | ||
}; | ||
|
||
export default useBreakpoint; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import useBreakpoint from "../useBreakpoint/useBreakpoint"; | ||
import { breakpoints as defaultBreakpoints } from "lib/theme/extensions/base"; | ||
|
||
import type { BreakpointToken } from "generated/panda/tokens"; | ||
|
||
/** | ||
* Get the closest value to the current breakpoint. This logic is taken from Chakra UI's `getClosestValue` function. | ||
* @see https://github.com/chakra-ui/chakra-ui/blob/bd3d0fd2f444be2ba23764d7c86906cb488fb409/packages/components/media-query/src/media-query.utils.ts#L3-L32 | ||
* @param values The arbitrary values to compare against. | ||
* @param breakpoint The current breakpoint. | ||
* @returns The closest value to the current breakpoint. | ||
*/ | ||
const getClosestValue = <T,>(values: Record<string, T>, breakpoint: string) => { | ||
const breakpoints = Object.keys(defaultBreakpoints); | ||
|
||
let index = Object.keys(values).indexOf(breakpoint); | ||
|
||
if (index !== -1) return values[breakpoint]; | ||
|
||
let stopIndex = breakpoints.indexOf(breakpoint); | ||
|
||
while (stopIndex >= 0) { | ||
const key = breakpoints[stopIndex]; | ||
|
||
if (values.hasOwnProperty(key)) { | ||
index = stopIndex; | ||
break; | ||
} | ||
stopIndex -= 1; | ||
} | ||
|
||
if (index !== -1) { | ||
const key = breakpoints[index]; | ||
return values[key]; | ||
} | ||
|
||
return undefined; | ||
}; | ||
|
||
export type Options<V> = Partial<Record<BreakpointToken, V>>; | ||
|
||
/** | ||
* Get conditional value based on theme breakpoints. | ||
*/ | ||
const useBreakpointValue = <V,>(values: Options<V>): V | undefined => { | ||
const breakpoint = useBreakpoint(); | ||
|
||
return getClosestValue(values, breakpoint); | ||
}; | ||
|
||
export default useBreakpointValue; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import useBreakpointValue from "lib/hooks/useBreakpointValue/useBreakpointValue"; | ||
|
||
const useIsMobile = () => useBreakpointValue({ base: true, sm: false }); | ||
|
||
export default useIsMobile; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* Device breakpoints for responsive design. | ||
*/ | ||
const breakpoints = { | ||
base: "0em", | ||
sm: "40em", | ||
md: "48em", | ||
lg: "64em", | ||
xl: "80em", | ||
"2xl": "96em", | ||
}; | ||
|
||
export default breakpoints; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { default as breakpoints } from "./breakpoints.base"; | ||
export { default as keyframes } from "./keyframes.base"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.