@pyreon/coolgrid 0.24.5 → 0.24.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,52 +0,0 @@
1
- import { useContext } from '@pyreon/core'
2
- import { get, pick } from '@pyreon/ui-core'
3
- import { context } from '@pyreon/unistyle'
4
- import { CONTEXT_KEYS } from './constants'
5
- import type { Context, Obj, ValueType } from './types'
6
-
7
- /**
8
- * Resolves grid columns and container width using a three-layer fallback:
9
- * 1. Explicit component props (e.g. `columns={6}`)
10
- * 2. `theme.grid.columns` / `theme.grid.container`
11
- * 3. `theme.coolgrid.columns` / `theme.coolgrid.container`
12
- */
13
- type GetGridContext = (
14
- props: Obj,
15
- theme: Obj,
16
- ) => {
17
- columns?: ValueType
18
- containerWidth?: Record<string, number>
19
- }
20
-
21
- export const getGridContext: GetGridContext = (props = {}, theme = {}) => ({
22
- // `props` is always a plain object (callers pass a `pick()` result or a
23
- // user-supplied object literal), so direct property access is safe and
24
- // skips `get`'s path-parsing for these single-key lookups. Ported from
25
- // vitus-labs `55402572`. Two `get` calls per `getGridContext` invocation
26
- // saved; fires once per Container/Row/Col render.
27
- columns: ((props as Obj).columns ||
28
- get(theme, 'grid.columns') ||
29
- get(theme, 'coolgrid.columns')) as ValueType,
30
- containerWidth: ((props as Obj).width ||
31
- get(theme, 'grid.container') ||
32
- get(theme, 'coolgrid.container')) as Record<string, number>,
33
- })
34
-
35
- /**
36
- * Hook that reads the unistyle theme context and merges it with the
37
- * component's own props to produce the final grid configuration.
38
- * Applies the three-layer resolution (props -> grid.* -> coolgrid.*).
39
- */
40
- type UseGridContext = (props: Obj) => Context
41
- const useGridContext: UseGridContext = (props) => {
42
- const getCtx = useContext(context)
43
- const { theme } = getCtx()
44
- // Direct `pick` (vs the `pickThemeProps` one-liner wrapper that was
45
- // removed in vitus-labs `55402572`) saves one function call per render.
46
- const ctxProps = pick(props, CONTEXT_KEYS as Array<keyof typeof props>)
47
- const gridContext = getGridContext(ctxProps, theme as Record<string, unknown>)
48
-
49
- return { ...gridContext, ...ctxProps }
50
- }
51
-
52
- export default useGridContext
package/src/utils.ts DELETED
@@ -1,23 +0,0 @@
1
- import { omit } from '@pyreon/ui-core'
2
- import { CONTEXT_KEYS } from './constants'
3
-
4
- /** Checks whether a value is a finite number. */
5
- export const isNumber = (value: unknown): value is number => Number.isFinite(value)
6
-
7
- /** Checks whether a value is a finite number greater than zero. */
8
- export const hasValue = (value: unknown): boolean => isNumber(value) && value > 0
9
-
10
- /**
11
- * Determines if a column should be visible. A column is visible when its
12
- * size is undefined (auto) or a non-zero number. Size 0 hides the column.
13
- */
14
- export const isVisible = (value: unknown): boolean =>
15
- (isNumber(value) && value !== 0) || value === undefined
16
-
17
- /** Returns true when both size and columns are positive numbers, indicating an explicit width can be calculated. */
18
- type HasWidth = (size: unknown, columns: unknown) => boolean
19
- export const hasWidth: HasWidth = (size, columns) => !!(hasValue(size) && hasValue(columns))
20
-
21
- /** Strips grid context keys from a props object so they are not forwarded to the DOM element. */
22
- type OmitCtxKeys = (props?: Record<string, any>) => ReturnType<typeof omit>
23
- export const omitCtxKeys: OmitCtxKeys = (props) => omit(props, CONTEXT_KEYS)