-
-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove incorrect imports from chakra ui
- Loading branch information
1 parent
eba6ac2
commit 0f49a18
Showing
9 changed files
with
83 additions
and
9 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,6 @@ | ||
--- | ||
'@saas-ui/hooks': patch | ||
'@saas-ui/core': patch | ||
--- | ||
|
||
Removed imports from @chakra-ui/react |
3 changes: 1 addition & 2 deletions
3
packages/saas-ui-core/src/components/grid-list/grid-list.context.ts
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,5 +1,3 @@ | ||
'use client' | ||
|
||
import { useCallback, useInsertionEffect, useRef } from 'react' | ||
|
||
/** | ||
|
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,67 @@ | ||
import { useCallback, useState } from 'react' | ||
|
||
import { useCallbackRef } from './use-callback-ref' | ||
|
||
export interface UseControllableStateProps<T> { | ||
/** | ||
* The value to used in controlled mode | ||
*/ | ||
value?: T | ||
/** | ||
* The initial value to be used, in uncontrolled mode | ||
*/ | ||
defaultValue?: T | (() => T) | ||
/** | ||
* The callback fired when the value changes | ||
*/ | ||
onChange?: (value: T) => void | ||
/** | ||
* The function that determines if the state should be updated | ||
*/ | ||
shouldUpdate?: (prev: T, next: T) => boolean | ||
} | ||
|
||
export function useControllableState<T>(props: UseControllableStateProps<T>) { | ||
const { | ||
value: valueProp, | ||
defaultValue, | ||
onChange, | ||
shouldUpdate = (prev, next) => prev !== next, | ||
} = props | ||
const onChangeProp = useCallbackRef(onChange) | ||
const shouldUpdateProp = useCallbackRef(shouldUpdate) | ||
|
||
const [valueState, setValue] = useState(defaultValue as T) | ||
|
||
const isControlled = valueProp !== undefined | ||
const value = isControlled ? (valueProp as T) : valueState | ||
|
||
const updateValue = useCallback( | ||
(next: React.SetStateAction<T>) => { | ||
const nextValue = runIfFn(next, value) | ||
|
||
if (!shouldUpdateProp(value, nextValue)) { | ||
return | ||
} | ||
|
||
if (!isControlled) { | ||
setValue(nextValue) | ||
} | ||
|
||
onChangeProp(nextValue) | ||
}, | ||
[isControlled, onChangeProp, value, shouldUpdateProp], | ||
) | ||
|
||
return [value, updateValue] as [T, React.Dispatch<React.SetStateAction<T>>] | ||
} | ||
|
||
const isFunction = (value: any): value is Function => | ||
typeof value === 'function' | ||
|
||
function runIfFn<T, U>( | ||
valueOrFn: T | ((...fnArgs: U[]) => T), | ||
...args: U[] | ||
): T { | ||
return isFunction(valueOrFn) ? valueOrFn(...args) : valueOrFn | ||
} |
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