@pyreon/coolgrid 0.24.4 → 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.
- package/package.json +9 -11
- package/src/Col/component.tsx +0 -61
- package/src/Col/index.ts +0 -3
- package/src/Col/styled.ts +0 -107
- package/src/Container/component.tsx +0 -80
- package/src/Container/index.ts +0 -3
- package/src/Container/styled.ts +0 -37
- package/src/Container/utils.ts +0 -13
- package/src/Row/component.tsx +0 -78
- package/src/Row/index.ts +0 -3
- package/src/Row/styled.ts +0 -70
- package/src/__tests__/Col.test.ts +0 -138
- package/src/__tests__/Container.styled.test.ts +0 -49
- package/src/__tests__/Container.test.ts +0 -152
- package/src/__tests__/Row.test.ts +0 -142
- package/src/__tests__/config.test.ts +0 -120
- package/src/__tests__/contextCascading.test.ts +0 -114
- package/src/__tests__/coolgrid.browser.test.tsx +0 -181
- package/src/__tests__/index.test.ts +0 -35
- package/src/__tests__/native-markers.test.ts +0 -13
- package/src/__tests__/useContext.test.ts +0 -92
- package/src/__tests__/utils.test.ts +0 -144
- package/src/constants.ts +0 -26
- package/src/context/ContainerContext.ts +0 -9
- package/src/context/RowContext.ts +0 -9
- package/src/context/index.ts +0 -4
- package/src/env.d.ts +0 -6
- package/src/index.ts +0 -7
- package/src/theme.ts +0 -40
- package/src/types.ts +0 -72
- package/src/useContext.tsx +0 -52
- package/src/utils.ts +0 -23
package/src/useContext.tsx
DELETED
|
@@ -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)
|