Skip to content
This repository has been archived by the owner on Nov 29, 2023. It is now read-only.

Commit

Permalink
foundation: rename screens -> breakpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
arnemolland committed Jul 23, 2022
1 parent 638dc64 commit abfe116
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/foundation/gameflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import {
Animations,
BorderRadius,
Breakpoints,
Colors,
Motion,
Screens,
Shadows,
Spacing,
Theme,
Expand Down Expand Up @@ -75,7 +75,7 @@ export const spacing: Spacing = {
xxl: '48px',
}

const screens: Screens = {
const breakpoints: Breakpoints = {
default: '0rem',
xs: '29rem',
sm: '36rem',
Expand Down Expand Up @@ -174,7 +174,7 @@ export const animations: Animations = {

export const gameflowTheme: Theme = {
colors,
screens,
breakpoints,
borderRadius,
motion,
shadows,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Flume breakpoints.
*/
export interface Screens {
export interface Breakpoints {
/**
* String index signature for type compat.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/foundation/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export * from './shadows.js'
export * from './spacing.js'
export * from './theme.js'
export * from './typography.js'
export * from './screens.js'
export * from './breakpoints.js'
export * from './animations.js'
4 changes: 2 additions & 2 deletions src/foundation/types/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Motion } from './motion.js'
import { Shadows } from './shadows.js'
import { Spacing } from './spacing.js'
import { Typography } from './typography.js'
import { Screens } from './screens.js'
import { Breakpoints } from './breakpoints.js'

export interface Theme {
colors: Colors
Expand All @@ -15,5 +15,5 @@ export interface Theme {
animations: Animations
borderRadius: BorderRadius
typography: Typography
screens: Screens
breakpoints: Breakpoints
}
20 changes: 10 additions & 10 deletions src/react/hooks/useBreakpoints.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { useTheme, useWindowDimensions } from './index.js'
import { Screens } from '~/foundation/index.js'
import { Breakpoints } from '~/foundation/index.js'

type NumberedBreakpoints = {
// eslint-disable-next-line no-unused-vars
[key in keyof Screens]: number
[key in keyof Breakpoints]: number
}

const parseBreakpoints = (breakpoints: Screens): NumberedBreakpoints => {
const parseBreakpoints = (breakpoints: Breakpoints): NumberedBreakpoints => {
const parsed: any = {}

for (const key in breakpoints) {
Expand All @@ -19,15 +19,15 @@ const parseBreakpoints = (breakpoints: Screens): NumberedBreakpoints => {

export interface BreakpointsProps {
breakpoints: NumberedBreakpoints
current: keyof Screens
current: keyof Breakpoints
isMobile: boolean
isDesktop: boolean
}

/** Retrieves a numbered version of the current Theme's breakpoints as well as the currently exceeded breakpoint */
export const useBreakpoints = () => {
const theme = useTheme()
const breakpoints = parseBreakpoints(theme.screens)
const breakpoints = parseBreakpoints(theme.breakpoints)
const current = useCurrentBreakpoint()
const dimensions = useWindowDimensions()

Expand All @@ -45,17 +45,17 @@ export const useBreakpoints = () => {

/** Retrieves the current Theme's breakpoints and returns them as numbers.*/
export const useNumberedBreakpoints = (): NumberedBreakpoints => {
const { screens } = useTheme()
return parseBreakpoints(screens)
const { breakpoints } = useTheme()
return parseBreakpoints(breakpoints)
}

/** Retrieves the currently exceeded breakpoint */
export const useCurrentBreakpoint = (): keyof Screens => {
export const useCurrentBreakpoint = (): keyof Breakpoints => {
const dimensions = useWindowDimensions()
const width = dimensions?.width

const { screens } = useTheme()
const parsed = parseBreakpoints(screens)
const { breakpoints } = useTheme()
const parsed = parseBreakpoints(breakpoints)

if (!width) {
return 'default'
Expand Down
4 changes: 2 additions & 2 deletions src/tailwind/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const getConfig = (theme: Theme = gameflowTheme): Partial<TailwindConfig>
shadows,
borderRadius,
animations: animation,
screens,
breakpoints,
typography,
motion,
} = theme
Expand All @@ -24,7 +24,7 @@ export const getConfig = (theme: Theme = gameflowTheme): Partial<TailwindConfig>
fontWeight,
borderRadius,
},
screens,
screens: breakpoints,
colors,
spacing,
animation,
Expand Down

0 comments on commit abfe116

Please sign in to comment.