-
-
Notifications
You must be signed in to change notification settings - Fork 427
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feature(helper): Extract `DeepPartial` to helper `DeepPartial` is a type that is identical to the built-in [Partial](https://www.typescriptlang.org/docs/handbook/utility-types.html#partialtype), but also allows nested partials. For example, the following causes type errors: ```js let somePartial: Partial<ComplexObject> = { some: { deeplyNestedThing: { oh: no } } } ``` * feature(type): Add theme for `Avatar`s * feature(type): Create `CustomFlowbiteTheme` type This is a more natural API to read than `DeepPartial<FlowbiteTheme>`. * feature(component): Rewrite `Avatar` to use themes, resolves #127 * test(component): Add theme unit test for `Avatar`s * feature(component): Prevent `className` on `Avatar`s Experimentally, destroy `className` if it is provided to `Avatar` to prevent the design from falling apart. * feature(helper): Add helper to exclude key from an object Additionally, provide a shortcut helper for the most common existing case, which is to remove `className` from a React component. * refactor(component): Add `excludeClassName` helper in `Avatar`
- Loading branch information
1 parent
87df117
commit 1a364fc
Showing
9 changed files
with
202 additions
and
72 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
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export type DeepPartial<T> = T extends object | ||
? { | ||
[P in keyof T]?: DeepPartial<T[P]>; | ||
} | ||
: T; |
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,34 @@ | ||
import exclude from './exclude'; | ||
|
||
describe('Helpers / Exclude (delete key from object)', () => { | ||
describe('Given object that contains targeted key', () => { | ||
it('should return input object without that key', () => { | ||
const input = { | ||
a: 1, | ||
b: 2, | ||
c: 3, | ||
}; | ||
const output = exclude({ key: 'a', source: input }); | ||
|
||
expect(output).toEqual({ | ||
b: 2, | ||
c: 3, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Given object that does not contain target key', () => { | ||
it('should return input object', () => { | ||
const input = { | ||
b: 2, | ||
c: 3, | ||
}; | ||
const output = exclude({ key: 'a', source: input }); | ||
|
||
expect(output).toEqual({ | ||
b: 2, | ||
c: 3, | ||
}); | ||
}); | ||
}); | ||
}); |
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,20 @@ | ||
import { PropsWithChildren } from 'react'; | ||
|
||
export interface ExcludeProps { | ||
key: string; | ||
source: Record<string, unknown>; | ||
} | ||
|
||
export const excludeClassName = (props: PropsWithChildren<object>): object => { | ||
return exclude({ | ||
key: 'className', | ||
source: props, | ||
}); | ||
}; | ||
|
||
const exclude = ({ key, source }: ExcludeProps): object => { | ||
delete source[key]; | ||
return source; | ||
}; | ||
|
||
export default exclude; |
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