-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
71 additions
and
43 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,22 @@ | ||
import * as React from "react"; | ||
import { useDisabled } from "./useDisabled"; | ||
import { useAllDisabled } from "./useAllDisabled"; | ||
import { EnableProps } from "./Enable"; | ||
|
||
/** | ||
* Feature will be disabled if any in the list are enabled | ||
*/ | ||
export const Disable: React.FC<EnableProps> = ({ | ||
feature = [], | ||
allFeatures = [], | ||
children | ||
}) => { | ||
const isAny = useDisabled(feature); | ||
const isAll = useAllDisabled(allFeatures); | ||
|
||
if (isAny || isAll) { | ||
return <>{children}</>; | ||
} | ||
|
||
return null; | ||
}; |
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,40 +1,11 @@ | ||
import { testAndConvert } from "./utils"; | ||
|
||
export type { EnableContextType } from "./EnableContext"; | ||
export type { FeatureContextType } from "./FeatureContext"; | ||
export { ToggleFeatures } from "./ToggleFeatures"; | ||
export { Features } from "./Features"; | ||
export { EnableContext } from "./EnableContext"; | ||
export { Enable } from "./Enable"; | ||
|
||
/** | ||
* returns true iff all specified features are enabled | ||
*/ | ||
export function useAllEnabled(allFeatures: string | string[]) { | ||
let [test, queryAllPresent] = testAndConvert(allFeatures); | ||
return queryAllPresent.every(test); | ||
} | ||
|
||
/** | ||
* returns true iff all specified features are disabled | ||
*/ | ||
export function useAllDisabled(withoutAll: string | string[]) { | ||
let [test, queryAllWithout] = testAndConvert(withoutAll); | ||
return queryAllWithout.every(x => !test(x)); | ||
} | ||
|
||
/** | ||
* returns true iff any specified feature is enabled | ||
*/ | ||
export function useEnabled(feature: string | string[]) { | ||
let [test, queryAnyPresent] = testAndConvert(feature); | ||
return queryAnyPresent.some(test); | ||
} | ||
|
||
/** | ||
* returns true iff any specified feature is disabled | ||
*/ | ||
export function useDisabled(without: string | string[]) { | ||
let [test, queryAnyWithout] = testAndConvert(without); | ||
return queryAnyWithout.some(x => !test(x)); | ||
} | ||
export { Disable } from "./Disable"; | ||
export { useDisabled } from "./useDisabled"; | ||
export { useEnabled } from "./useEnabled"; | ||
export { useAllDisabled } from "./useAllDisabled"; | ||
export { useAllEnabled } from "./useAllEnabled"; |
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,10 @@ | ||
import { testAndConvert } from "./utils"; | ||
|
||
/** | ||
* returns true iff all specified features are disabled | ||
*/ | ||
|
||
export function useAllDisabled(withoutAll: string | string[]) { | ||
let [test, queryAllWithout] = testAndConvert(withoutAll); | ||
return queryAllWithout.every(x => !test(x)); | ||
} |
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,10 @@ | ||
import { testAndConvert } from "./utils"; | ||
|
||
/** | ||
* returns true iff all specified features are enabled | ||
*/ | ||
|
||
export function useAllEnabled(allFeatures: string | string[]) { | ||
let [test, queryAllPresent] = testAndConvert(allFeatures); | ||
return queryAllPresent.every(test); | ||
} |
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,10 @@ | ||
import { testAndConvert } from "./utils"; | ||
|
||
/** | ||
* returns true iff any specified feature is disabled | ||
*/ | ||
|
||
export function useDisabled(without: string | string[]) { | ||
let [test, queryAnyWithout] = testAndConvert(without); | ||
return queryAnyWithout.some(x => !test(x)); | ||
} |
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,10 @@ | ||
import { testAndConvert } from "./utils"; | ||
|
||
/** | ||
* returns true iff any specified feature is enabled | ||
*/ | ||
|
||
export function useEnabled(feature: string | string[]) { | ||
let [test, queryAnyPresent] = testAndConvert(feature); | ||
return queryAnyPresent.some(test); | ||
} |
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