-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add live demo to privacy shield
- Loading branch information
Showing
4 changed files
with
69 additions
and
8 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 |
---|---|---|
@@ -1,28 +1,46 @@ | ||
--- | ||
title: <PrivacyShield /> | ||
--- | ||
|
||
import { PrivacyShield } from '@consent-manager/core'; | ||
import { DisableButton } from '../../src/components/disable-button'; | ||
|
||
# `<PrivacyShield />` | ||
|
||
`PrivacyShield` is a component that conditionally renders children based on the consent decision for a specific integration. It's typically used to wrap content that should only be displayed if the user has consented to the associated integration. | ||
|
||
## Props | ||
| Prop | Type | Description | | ||
|--------------|-----------------------------|--------------------------------------------------------------| | ||
| `id` | `string` | The identifier for the integration to check consent for. | | ||
| `children` | `React.ReactNode` | The content to render if consent is given. | | ||
| `...props` | `unknown` | Additional props passed to the fallback component. | | ||
|
||
| Prop | Type | Description | | ||
| ---------- | ----------------- | -------------------------------------------------------- | | ||
| `id` | `string` | The identifier for the integration to check consent for. | | ||
| `children` | `React.ReactNode` | The content to render if consent is given. | | ||
| `...props` | `unknown` | Additional props passed to the fallback component. | | ||
|
||
## Prefer a Custom Placeholder or Fallback Component? | ||
|
||
Set it up globally using the `fallbackComponent` property in the [`ConsentManager` component](./consent-manager.md). | ||
|
||
## Example Usage | ||
|
||
```jsx | ||
import { PrivacyShield } from '@consent-manager/core'; | ||
import { PrivacyShield } from '@consent-manager/core' | ||
|
||
const YouTubeEmbed = ({ videoId }) => ( | ||
<PrivacyShield id="youtube"> | ||
{/* Your YouTube embed component */} | ||
</PrivacyShield> | ||
); | ||
``` | ||
) | ||
``` | ||
|
||
### Example Rendering | ||
|
||
Here's an example of what a shield will appear as: | ||
|
||
<PrivacyShield id="demo"> | ||
<center> | ||
<h4>Looking for the privacy shield?</h4> | ||
<p>The demo integration has been enabled!</p> | ||
<DisableButton id="demo">Display Privacy Shield</DisableButton> | ||
</center> | ||
</PrivacyShield> |
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,14 @@ | ||
import React from 'react' | ||
import { useDecision } from '@consent-manager/core' | ||
|
||
export function DisableButton({ | ||
children, | ||
id, | ||
}: { | ||
children: React.ReactNode | ||
id: string | ||
}) { | ||
const [, setEnabled]= useDecision(id) | ||
|
||
return <button onClick={() => setEnabled(false)}>{children}</button> | ||
} |
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,27 @@ | ||
import { siCreativecommons } from 'simple-icons' | ||
|
||
import { | ||
createIconComponentFromSimpleIconsSvgPath, | ||
getForegroundColor, | ||
IntegrationConfig, | ||
} from '@consent-manager/core' | ||
|
||
export function demoIntegration(): IntegrationConfig { | ||
const { title, hex, path } = siCreativecommons | ||
const color = `#${hex}` | ||
const contrastColor = getForegroundColor(color) | ||
const Icon = createIconComponentFromSimpleIconsSvgPath(title, path) | ||
const lang = | ||
typeof window !== 'undefined' ? window.navigator.language : 'en-US' | ||
|
||
return { | ||
id: 'demo', | ||
title: 'Demo Integration', | ||
category: 'Demo', | ||
color, | ||
contrastColor, | ||
Icon, | ||
privacyPolicyUrl: `https://example.com?hl=${lang}`, | ||
description: 'Please: Keep me disabled for the privacy shield demo in the docs :)', | ||
} | ||
} |