Skip to content

Commit

Permalink
Adds the watermark component (#6)
Browse files Browse the repository at this point in the history
Adds a simple watermark component
  • Loading branch information
Krakabek authored Aug 2, 2024
1 parent f0d33c4 commit 3d18f39
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 14 deletions.
28 changes: 14 additions & 14 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
# Devvit-kit
# Devvit Kit

Devvit Kit is a helper library that makes it easier to build [Devvit apps](https://developers.reddit.com),
or apps on Reddit’s developer platform.
Kit includes both UI components and general backend patterns that simplifies common tasks and enables developers to
Devvit Kit is a helper library that makes it easier to build [Devvit apps](https://developers.reddit.com)
and apps on Reddit’s Developer Platform. Devvit Kit includes both UI components and general backend patterns that simplify common tasks and enable developers to
build apps faster.

## Installation

To use Kit, navigate to your devvit project in your terminal and install the package:
To use Devvit Kit, navigate to your Devvit project in your terminal and install the package:

`npm install @devvit/kit`

## Usage

Once you have Kit installed, you can import the helper you’re trying to use and then use it in applicable pieces of
Once you have Devvit Kit installed, you can import the helper you’re trying to use and then use it in applicable pieces of
code. This is an example using the Columns helper.

```typescript jsx
Expand All @@ -34,12 +33,13 @@ Devvit.addCustomPostType({
});
```

| Component Name | Description | Links |
| ----------------- | ----------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------- |
| Columns | A component that provides a simple column layout and optionally allows you to specify gap sizing between elements | [Usage Instructions](./src/columns/readme.md) |
| Item pagination | A helper that enables pagination of data including UI elements for navigating through the elements | [Usage Instructions](./src/item-pagination/readme.md) |
| PixelPadding | A component that lets you set padding from any side using pixel values. | [Usage Instructions](./src/pixel-padding/readme.md) |
| Developer toolbar | Adds a toolbar of actions only visible to developers | [Usage Instructions](./src/dev-toolbar/readme.md) |
| Component Name | Description | Links |
| ----------------- | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------ |
| Columns | A component that provides a simple column layout and optionally allows you to specify gap sizing between elements. | [Usage Instructions](./src/columns/readme.md) |
| Item pagination | A helper that enables pagination of data, including UI elements for navigating through the elements. | [Usage Instructions](./src/item-pagination/readme.md) |
| PixelPadding | A component that lets you set padding from any side using pixel values. | [Usage Instructions](./src/pixel-padding/readme.md) |
| Developer toolbar | A toolbar of actions only visible to developers. | [Usage Instructions](./src/dev-toolbar/readme.md) |
| Watermark | A Developer Platform watermark that's added to your app. | [Usage Instructions](./src/devvit-watermark/readme.md) |

## Contributing to the devvit-kit public repo

Expand All @@ -48,9 +48,9 @@ There's a [public issue board](https://github.com/reddit/devvit-kit/issues) that
All feedback is welcome!

If you'd like to contribute to this repo as developer, you can find detailed instructions
in [contributing.md](contributing.md)
in the [contributing](contributing.md) file.

## Contributor License Agreement
## Contributor license agreement

The first time you submit a pull request (PR) to a Reddit
project, [you should complete our CLA](https://docs.google.com/forms/d/e/1FAIpQLScG6Bf3yqS05yWV0pbh5Q60AsaXP2mw35_i7ZA19_7jWNJKsg/viewform).
Expand Down
132 changes: 132 additions & 0 deletions src/devvit-watermark/DevvitWatermark.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import { Devvit } from "@devvit/public-api";

/**
* @field appName - the app name that is specified in devvit.yaml.
*
* @field developer - username of the app creator.
*/
export type WatermarkProps = { appName: string; developer: string };

/**
* A component that appends the watermark to the container it is wrapped around
*/
export const DevvitWatermarkWrapper: Devvit.BlockComponent<WatermarkProps> = (
props,
) => {
return (
<vstack height={100} width={100}>
<vstack grow width={100}>
{props.children}
</vstack>
<DevvitWatermark appName={props.appName} developer={props.developer} />
</vstack>
);
};

/**
* A component that places the watermark over the container it is wrapped around
*/
export const DevvitWatermarkOverlay: Devvit.BlockComponent<WatermarkProps> = (
props,
) => {
return (
<zstack height={100} width={100} alignment="bottom center">
<vstack height={100} width={100}>
{props.children}
</vstack>
<DevvitWatermark appName={props.appName} developer={props.developer} />
</zstack>
);
};

/**
* A watermark component. Renders Devvit logo, link to the author profile page and link to the app details
* @param appName - the app name that is specified in devvit.yaml
* @param developer - username of the app creator
*/
const DevvitWatermark: Devvit.BlockComponent<WatermarkProps> = (
props,
context,
) => {
const is1stPartyApp = props.developer === "Reddit";

return (
<vstack
darkBackgroundColor="#04090A"
lightBackgroundColor="#F5F5F5"
height="32px"
width={100}
>
<hstack height={"1px"} grow darkBackgroundColor="#FFFFFF1A"></hstack>
<hstack height={100}>
<spacer size="small" />
<hstack gap="small" grow alignment="start middle">
<DevvitLogo />
<hstack>
<hstack alignment="start middle">
<text
size="small"
darkColor="#B8C5C9"
lightColor="#000"
selectable={false}
>
{is1stPartyApp ? "Built on" : "Built by"}
</text>
<text selectable={false}>&nbsp;</text>
<vstack
onPress={() =>
context.ui.navigateTo(
is1stPartyApp
? `https://developers.reddit.com?utm_medium=watermark&utm_source=${props.appName}`
: `https://www.reddit.com/user/${props.developer}/`,
)
}
>
<text
size="small"
darkColor="#B8C5C9"
lightColor="#000"
selectable={false}
>
{is1stPartyApp ? "DevPlatform" : props.developer}
</text>
<hstack height={"1px"} backgroundColor="#B8C5C9"></hstack>
</vstack>
</hstack>
</hstack>
</hstack>
<hstack>
<vstack
onPress={() =>
context.ui.navigateTo(
`https://developers.reddit.com/apps/${props.appName}`,
)
}
alignment="middle"
>
<text
size="small"
darkColor="#B8C5C9"
lightColor="#000"
selectable={false}
>
Details
</text>
<hstack height={"1px"} backgroundColor="#B8C5C9"></hstack>
</vstack>
</hstack>
<spacer size="small" />
</hstack>
</vstack>
);
};

function DevvitLogo(): JSX.Element {
return (
<image
imageHeight={14}
imageWidth={14}
url={"https://i.redd.it/llj3dnlz1ufd1.png"}
/>
);
}
38 changes: 38 additions & 0 deletions src/devvit-watermark/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Devvit watermark

A watermark indicates that your app was built on Developer Platform.

<img src="https://i.redd.it/cdnom5lo41gd1.png" alt="Usage example: 'Built by kebakark. Details'">

You can add a watermark to your app in one of two ways:

- `DevvitWatermarkWrapper` appends the watermark to the container it is wrapped around. This reduces the space available in the container, but the watermark does not overlap with the content.
- `DevvitWatermarkOverlay` places the watermark over the container it is wrapped around. This does not reduce the space available in the container, and the watermark overlaps with the content.

## How to use

### Step 1: Install Devvit Kit

Open your project folder in the terminal app.

Run `npm install @devvit/kit --save`

### Step 2: Import the `DevvitWatermarkWrapper` or `DevvitWatermarkOverlay` component

Add the line `import { DevvitWatermarkWrapper } from '@devvit/kit';` in the beginning of the component file.

### Step 3: Use the watermark in your app

Wrap the `DevToolbarWrapper` around the top element of your root component, like this:

```typescript jsx
return (
<DevvitWatermarkWrapper appName="my-cool-app" developer="username">
<hstack width={100} height={100}>
...
</hstack>
</DevvitWatermarkWrapper>
);
```

Make sure that `appName` matches the `name` in the `devvit.yaml` in your project folder and `developer` matches your Reddit username
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from "./dev-toolbar/index.js";
export * from "./columns/index.js";
export * from "./item-pagination/index.js";
export * from "./pixel-padding/index.js";
export * from "./devvit-watermark/DevvitWatermark.js";

0 comments on commit 3d18f39

Please sign in to comment.