Skip to content

Commit

Permalink
feat: first version
Browse files Browse the repository at this point in the history
  • Loading branch information
Mon4ik committed Mar 12, 2024
0 parents commit 93b0f22
Show file tree
Hide file tree
Showing 35 changed files with 4,618 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"jsx": true,
"useJSXTextNode": true,
"ecmaVersion": 2018,
"sourceType": "module",
"project": "./tsconfig.json"
},
"ignorePatterns": ["/out"],
"plugins": ["@typescript-eslint", "roblox-ts", "unused-imports", "simple-import-sort"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:roblox-ts/recommended"
],
"rules": {
"unused-imports/no-unused-imports": "warn",
"simple-import-sort/imports": "warn",
"simple-import-sort/exports": "warn"
}
}
28 changes: 28 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Build package
on:
- push
- pull_request

jobs:
build:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v3

- uses: pnpm/action-setup@v2
with:
version: 8

- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: 18
registry-url: 'https://registry.npmjs.org'
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Build package
run: pnpm build
36 changes: 36 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Release

on:
push:
branches:
- main

jobs:
release:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8

- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: 20
registry-url: 'https://registry.npmjs.org'
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Build package
run: pnpm build

- name: Semantic Release
run: pnpm semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/node_modules
/out
/include

.DS_Store
*.tsbuildinfo
*.log

rbxts-better-react-components-*.tgz
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node-linker=hoisted
16 changes: 16 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"branches": [
"main"
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/npm",
[
"@semantic-release/git",
{
"assets": ["package.json"],
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}
]
]
}
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Better React Components

Roblox's elements, with builtin modifiers

Also see **[introduction](docs/1_Introduction.md)**

## Example

```tsx
<Frame
position={new UDim2(.5, 0, .5, 0)}
size={new UDim2(.5, 0, .5, 0)}

anchorPoint={"m"}
cornerRadius={8}
padding={4}
>
<GridLayout
cellSize={new UDim2(.25, 0, .25, 0)}
cellPadding={new UDim2(0, 4, 0, 4)}
cellAspectRatio={1}
/>

<DummyElement />
<Button
position={new UDim2(0, 0, 0, 0)} size={new UDim2(0, 0, 0, 0)}
textColor={Color3.fromHex("#64FEE7")}
text="Hello world!"
/>
<Text
position={new UDim2(0, 0, 0, 0)} size={new UDim2(0, 0, 0, 0)}
background={Color3.fromHex("#64FEE7")
text="Hello world!"
/>
</Frame>;
```
94 changes: 94 additions & 0 deletions docs/1_Introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Introduction
<u>Introduction</u> • [Modifiers](2_Modifiers.md)[Components](3_Components.md)

> **Warning**
>
> Documentation is still in development. Best way to learn it – check out source code
>
> - [Base component](../src/expandBase.tsx)
> - [Frame](../src/components/Frame.tsx)
> - [Text](../src/components/Text.tsx)
> - [Button](../src/components/Button.tsx)
> - _And other components at [/src/components/](../src/components/)_
>
## Why?
This package can help You with Roblox's UI Modifiers

#### Before:
```tsx
<frame
Position={new UDim2(.5, 0, .5, 0)}
Size={new UDim2(.5, 0, .5, 0)}
AnchorPoint={new Vector2(.5, .5)}
>
<uigridlayout
CellSize={new UDim2(.25, 0, .25, 0)}
CellPadding={new UDim2(0, 4, 0, 4)}
>
<uiaspectratioconstraint AspectRatio={1} />
</uigridlayout>

<frame />
<frame />
<frame />
</frame>;
```

#### After:
```tsx
<Frame
position={new UDim2(.5, 0, .5, 0)}
size={new UDim2(.5, 0, .5, 0)}
anchorPoint={"m"} // m - middle
// or anchorPoint={AnchorPoints.Middle}
// or anchorPoint={new Vector2(.5, .5)}
>
<GridLayout
cellSize={new UDim2(.25, 0, .25, 0)}
cellPadding={new UDim2(0, 4, 0, 4)}
cellAspectRatio={1}
/>

<frame />
<frame />
<frame />
</Frame>
```


## Installation
Pro tip: use [this @rbxts/react template](https://github.com/littensy/rbxts-react-example)
```bash
# install with any package manager:
pnpm add @rbxts/better-react-components
yarn add @rbxts/better-react-components
npm install @rbxts/better-react-components
```

## Usage:
```tsx
// import any component
import { Frame, Text } from "@rbxts/better-react-components";

...

// and use it!
return (
<Frame>
<Text text="Hello world!" />
</Frame>
);

...
```

## Unusual behaviours
1. By default, `Text`'s background is transparent
```tsx
<Text text="Hello world!" />; // background IS transparent
<Text
text="Hello world!"
backgroundTransparency={0}
/>; // background IS NOT transparent
```
93 changes: 93 additions & 0 deletions docs/2_Modifiers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Modifiers && Utils

[Introduction](1_Introduction.md) • <u>Modifiers</u> • [Components](3_Components.md)

Roblox UI Modifiers, but in simpler way

## Modifiers

### Corner Radius

```tsx
<Frame
cornerRadius={8}
// or cornerRadius={new UDim(0, 8)} (same)
>
...
</Frame>;
```

### Aspect Ratio

```tsx
<Frame
aspectRatio={1}
// aspectType={Enum.AspectType}
// aspectAxis={Enum.DominantAxis}
>
...
</Frame>;
```

### Stroke

```tsx
<Frame
stroke={{ /* roblox props for UIStroke*/ }}
>
...
</Frame>;
```

### Padding

```tsx
<Frame
padding={4} // for top, left, bottom, right

// or individually:
// paddingTop={4}
// paddingLeft={4}
// paddingBottom={4}
// paddingRight={4}
>
...
</Frame>;
```

## Utils

Some utils, used for building this components

### AnchorPoints

```tsx
import { AnchorPoints } from "@rbxts/better-react-components";

<Frame anchorPoint={AnchorPoints.TopLeft} />;
<Frame anchorPoint={AnchorPoints.Middle} />;
<Frame anchorPoint={AnchorPoints.BottomRight} />;
```

### resolveAnchorPoint

```tsx
import { AnchorPoints, resolveAnchorPoint } from "@rbxts/better-react-components";

resolveAnchorPoint("m") // Vector2(.5, .5)
resolveAnchorPoint(AnchorPoints.BottomRight) // Vector2(1, 1)

resolveAnchorPoint(new Vector2(x, y)) // Vector2(x, y)
```

### resolveUDim

```tsx
import { resolveUDim } from "@rbxts/better-react-components";

resolveUDim(8) // UDim(0, 8)
resolveUDim(n) // UDim(0, n)

resolveUDim(new UDim(a, b)) // UDim(a, b)

```
6 changes: 6 additions & 0 deletions docs/3_Components.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Components
[Introduction](1_Introduction.md)[Modifiers](2_Modifiers.md) • <u>Components</u>

List of components and its props

> **check out [/src/components/](../src/components/)**
6 changes: 6 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/node_modules
/out
/include
*.tsbuildinfo
yarn-error.log
.DS_Store
1 change: 1 addition & 0 deletions example/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node-linker=hoisted
7 changes: 7 additions & 0 deletions example/aftman.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file lists tools managed by Aftman, a cross-platform toolchain manager.
# For more information, see https://github.com/LPGhatguy/aftman

# To add a new tool, add an entry to this table.
[tools]
rojo = "rojo-rbx/[email protected]"
# rojo = "rojo-rbx/[email protected]"
Loading

0 comments on commit 93b0f22

Please sign in to comment.