diff --git a/apps/docs/.eslintrc.json b/apps/docs/.eslintrc.json index 66d9a5c27..891dea474 100644 --- a/apps/docs/.eslintrc.json +++ b/apps/docs/.eslintrc.json @@ -29,7 +29,8 @@ "PackageInstallation": true, "PropTable": true, "CodeOnlyExample": true, - "Example": true + "Example": true, + "FeatureFlag": true }, "overrides": [ { @@ -57,21 +58,31 @@ ], "react/destructuring-assignment": "off", "no-param-reassign": "off", - "no-restricted-imports": ["error", { - "patterns": [ - { - "group": ["../../index.ts", "../index.ts", "../../../index.ts", "./index.ts"], - "message": "Avoid importing from index.ts files directly next or above the current file" - } - ], - "paths": [ - { - "name": "react", - "importNames": ["default"], - "message": "import React from \"react\" is no longer necessary and should be avoided. " - } - ] - }] + "no-restricted-imports": [ + "error", + { + "patterns": [ + { + "group": [ + "../../index.ts", + "../index.ts", + "../../../index.ts", + "./index.ts" + ], + "message": "Avoid importing from index.ts files directly next or above the current file" + } + ], + "paths": [ + { + "name": "react", + "importNames": [ + "default" + ], + "message": "import React from \"react\" is no longer necessary and should be avoided. " + } + ] + } + ] } } ] diff --git a/apps/docs/components/featureFlag/FeatureFlag.tsx b/apps/docs/components/featureFlag/FeatureFlag.tsx new file mode 100644 index 000000000..34852de9c --- /dev/null +++ b/apps/docs/components/featureFlag/FeatureFlag.tsx @@ -0,0 +1,17 @@ +"use client"; + +import { useContext, type ReactNode } from "react"; +import { FeatureFlagContext } from "@/context/feature/FeatureFlagProvider.tsx"; + +interface FeatureFlagProps { + flag: string; + children: ReactNode; +} + +const FeatureFlag = ({ flag, children }: FeatureFlagProps) => { + const featureFlags = useContext(FeatureFlagContext); + + return featureFlags[flag] ? children : null; +}; + +export default FeatureFlag; diff --git a/apps/docs/components/mdx/components.tsx b/apps/docs/components/mdx/components.tsx index b3efebb1d..c8fbd59de 100644 --- a/apps/docs/components/mdx/components.tsx +++ b/apps/docs/components/mdx/components.tsx @@ -33,6 +33,7 @@ import SimpleTable from "@/app/ui/components/simpleTable/SimpleTable"; const MigrateGuide = dynamic(() => import("@/app/ui/components/migrateGuide/MigrateGuide.tsx")); const PropTable = dynamic(() => import("@/app/ui/components/propTable/PropTable.tsx")); const ComponentExample = dynamic(() => import("@/app/ui/components/componentExample/ComponentExample.tsx")); +const FeatureFlag = dynamic(() => import("@/components/featureFlag/FeatureFlag.tsx")); type HeadingProps = DetailedHTMLProps, HTMLHeadingElement>; @@ -55,6 +56,7 @@ export const components = { Tabs: Tabs, TableSection: TableSection, Switcher: Switcher, + FeatureFlag: FeatureFlag, PackageInstallation: (props: PackageInstallationProps) => { return ; }, diff --git a/apps/docs/content/components/buttons/Button.mdx b/apps/docs/content/components/buttons/Button.mdx index 65938d5e8..6c3c2d123 100644 --- a/apps/docs/content/components/buttons/Button.mdx +++ b/apps/docs/content/components/buttons/Button.mdx @@ -12,21 +12,25 @@ links: -## Guidelines + + ## Guidelines -TODO: If we have some guidelines about this component's usage + TODO: If we have some guidelines about this component's usage -### Accessibility ? + ### Accessibility ? -TODO: If we have some guidelines about this component and accessibility + TODO: If we have some guidelines about this component and accessibility + -## Anatomy + + ## Anatomy -TODO: We have anatomy screenshots from the Figma, we could most likely use them here + TODO: We have anatomy screenshots from the Figma, we could most likely use them here -### Concepts + ### Concepts -- [Client Side Routing](./client-side-routing) + - [Client Side Routing](./client-side-routing) + ### Composed Components @@ -98,23 +102,25 @@ A button can be rendered as a react router link when using the href property, an -## Advanced customization + + ## Advanced customization -### Contexts + ### Contexts -All Hopper Components exports a corresponding context that can be used to send props to them from a parent element. -You can send any prop or ref via context that you could pass to the corresponding component. -The local props and ref on the component are merged with the ones passed via context, with the local props taking precedence + All Hopper Components exports a corresponding context that can be used to send props to them from a parent element. + You can send any prop or ref via context that you could pass to the corresponding component. + The local props and ref on the component are merged with the ones passed via context, with the local props taking precedence - + -### Custom Children + ### Custom Children -TODO: Example of passing custom childrens to the components to fake a slot + TODO: Example of passing custom childrens to the components to fake a slot -### Custom Component + ### Custom Component -TODO: Example of creating a custom version of this component + TODO: Example of creating a custom version of this component + ## Migration Notes (WIP) diff --git a/apps/docs/context/feature/FeatureFlagProvider.tsx b/apps/docs/context/feature/FeatureFlagProvider.tsx index 2e03a6326..870c4e3c4 100644 --- a/apps/docs/context/feature/FeatureFlagProvider.tsx +++ b/apps/docs/context/feature/FeatureFlagProvider.tsx @@ -1,18 +1,11 @@ "use client"; import { createContext, type ReactNode } from "react"; +import { flags } from "./flags.ts"; -export interface FeatureFlags { - alpha?: boolean; -} - -export const FeatureFlagContext = createContext({}); +export const FeatureFlagContext = createContext>({}); export const FeatureFlagProvider = ({ children }: { children: ReactNode }) => { - const flags = { - alpha: process.env.NEXT_PUBLIC_ALPHA === "true" - }; - return ( {children} diff --git a/apps/docs/context/feature/flags.ts b/apps/docs/context/feature/flags.ts new file mode 100644 index 000000000..cc6d6e190 --- /dev/null +++ b/apps/docs/context/feature/flags.ts @@ -0,0 +1,5 @@ +export const flags = { + alpha: process.env.NEXT_PUBLIC_ALPHA === "true", + rc: process.env.NEXT_PUBLIC_RC === "true", + next: process.env.NEXT_PUBLIC_NEXT === "true" +};