Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UI monorepo package #56

Draft
wants to merge 9 commits into
base: release
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,16 @@
"unicorn/filename-case": "off",
"max-depth": "off"
},
"overrides": [
{
"files": ["packages/**/*"],
"rules": {
"semi": [
"error",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why add? not clear. half of the project uses it and the other doesn't.

"always"
]
}
}
],
"root": true
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"test-mc-server": "tsx cypress/minecraft-server.mjs",
"lint": "eslint \"{src,cypress}/**/*.{ts,js,jsx,tsx}\"",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build && node scripts/build.js moveStorybookFiles",
"build-storybook": "storybook build -o dist/storybook && node scripts/build.js moveStorybookFiles",
"start-experiments": "vite --config experiments/vite.config.ts",
"watch-worker": "node prismarine-viewer/buildWorker.mjs -w"
},
Expand All @@ -29,6 +29,7 @@
"dependencies": {
"@dimaka/interface": "0.0.3-alpha.0",
"@floating-ui/react": "^0.26.1",
"@prismarine-web-client": "link:packages/ui",
"@types/react": "^18.2.20",
"@types/react-dom": "^18.2.7",
"@types/wicg-file-system-access": "^2023.10.2",
Expand Down
11 changes: 11 additions & 0 deletions packages/ui/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my standard prettier config that i use across all projects (also aligns with this project)

Suggested change
{
{
"semi": false,
"singleQuote": true,
"proseWrap": "never",
"tabWidth": 4,
"trailingComma": "all",
"arrowParens": "avoid",
"printWidth": 160,
"endOfLine": "auto"
}

Copy link
Author

@egorprnn egorprnn Jan 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Сможешь ли его вынести в корень проекта - отформатировав его весь после этого, чтобы я мог его активировать у себя и убрать этот?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont really understand what the problem is on your side...
unfortunately, i can't use prettier for the whole project because of its specifics e.g. in some files it makes code less readable

"printWidth": 120,
"tabWidth": 2,
"bracketSpacing": true,
"bracketSameLine": false,
"singleQuote": true,
"trailingComma": "all",
"arrowParens": "always",
"semi": true,
"quoteProps": "consistent"
}
19 changes: 19 additions & 0 deletions packages/ui/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { StorybookConfig } from '@storybook/react-vite';

const config: StorybookConfig = {
stories: ['../src/**/*.stories.@(ts|tsx)', '../src/**/*.mdx'],
addons: ['@storybook/addon-essentials', '@storybook/addon-interactions'],
core: {
disableTelemetry: true,
disableWhatsNewNotifications: true,
},
framework: {
name: '@storybook/react-vite',
options: {},
},
docs: {
autodocs: 'tag',
},
};

export default config;
15 changes: 15 additions & 0 deletions packages/ui/.storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Preview } from '@storybook/react';

const preview: Preview = {
parameters: {
actions: { argTypesRegex: '^on[A-Z].*' },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
},
};

export default preview;
32 changes: 32 additions & 0 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "@prismarine-web-client/ui",
"version": "1.0.0",
"main": "./src/index.ts",
"scripts": {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add private: true for now we're not going to publish it since I don't own @prismarine-web-client

"storybook:start": "storybook dev -p 6006",
"storybook:build": "storybook build",
"------------------------------------------------------": "",
"prettier:fix": "prettier --write './**/*.{ts,tsx}'",
"prettier:check": "prettier --check './**/*.{ts,tsx}'"
},
"peerDependencies": {
"classnames": "^2.5.1",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why peer

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Базовый проект уже имеет эту зависимость - при обновлении в базовом проекте, можем забыть обновить здесь, тогда будет установлено две зависимости одного пакета с разными версиями - возникнет дубль

"react": "^18.2.0"
},
"devDependencies": {
"@storybook/addon-essentials": "^7.4.6",
"@storybook/addon-interactions": "^7.4.6",
"@storybook/addon-links": "^7.4.6",
"@storybook/addon-onboarding": "^1.0.8",
"@storybook/blocks": "^7.4.6",
"@storybook/react": "^7.4.6",
"@storybook/react-vite": "^7.4.6",
"@storybook/testing-library": "^0.2.2",
"@types/react-dom": "^18.2.14",
"classnames": "^2.5.1",
"prettier": "^3.2.1",
"react-dom": "^18.2.0",
"storybook": "^7.4.6",
"vite": "^4.5.0"
}
}
6 changes: 6 additions & 0 deletions packages/ui/src/components/AppRoot/AppRoot.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.root {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;

font-family: minecraft, mojangles, monospace;
}
10 changes: 10 additions & 0 deletions packages/ui/src/components/AppRoot/AppRoot.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import classNames from 'classnames';
import { HTMLAttributes } from 'react';

import styles from './AppRoot.module.css';

export interface AppRootProps extends HTMLAttributes<HTMLDivElement> {}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to use ComponentType<'div'> for singularity.

For the same reason, I think its better to not export these interfaces and in other files do something like ComponentType<typeof AppRoot> since its a recommended react approach IMO. Overall this would be more logical and easier to understand

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, i mean ComponentProps


export const AppRoot = ({ className, ...restProps }: AppRootProps) => {
return <div className={classNames(styles.root, className)} {...restProps} />;
};
1 change: 1 addition & 0 deletions packages/ui/src/components/AppRoot/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { AppRoot, type AppRootProps } from './AppRoot';
18 changes: 18 additions & 0 deletions packages/ui/src/components/RootComponent/RootComponent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import classNames from 'classnames';
import { AllHTMLAttributes } from 'react';

import { HasComponent, HasRootRef } from '../../types';

export interface RootComponentProps<T> extends AllHTMLAttributes<T>, HasRootRef<T>, HasComponent {
baseClassName?: string | false;
}

export const RootComponent = <T,>({
Component = 'div',
getRootRef,
baseClassName,
className,
...restProps
}: RootComponentProps<T>) => {
return <Component ref={getRootRef} className={classNames(baseClassName, className)} {...restProps} />;
};
1 change: 1 addition & 0 deletions packages/ui/src/components/RootComponent/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './RootComponent';
3 changes: 3 additions & 0 deletions packages/ui/src/components/Typography/Text/Text.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.root {
font-size: var(--ui_font_size_text);
}
10 changes: 10 additions & 0 deletions packages/ui/src/components/Typography/Text/Text.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import classNames from 'classnames';
import { Typography, TypographyProps } from '../Typography';

import styles from './Text.module.css';

export type TextProps = TypographyProps;

export const Text = ({ Component = 'span', className, ...restProps }: TextProps) => {
return <Typography Component={Component} className={classNames(styles.root, className)} {...restProps} />;
};
1 change: 1 addition & 0 deletions packages/ui/src/components/Typography/Text/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Text, type TextProps } from './Text';
Loading