1 Commits

Author SHA1 Message Date
8e798f84d1 Add example with mantine tests package 2023-11-19 19:07:26 +04:00
27 changed files with 9260 additions and 8690 deletions

3
.eslintignore Normal file
View File

@ -0,0 +1,3 @@
*.cjs
*.mjs
*.js

17
.eslintrc.cjs Normal file
View File

@ -0,0 +1,17 @@
module.exports = {
extends: ['mantine', 'plugin:@next/next/recommended', 'plugin:jest/recommended'],
plugins: ['testing-library', 'jest'],
overrides: [
{
files: ['**/?(*.)+(spec|test).[jt]s?(x)'],
extends: ['plugin:testing-library/react'],
},
],
parserOptions: {
project: './tsconfig.json',
},
rules: {
'react/react-in-jsx-scope': 'off',
'import/extensions': 'off',
},
};

View File

@ -1,27 +0,0 @@
name: npm test
on:
pull_request:
branches:
- '**'
concurrency:
group: ${{ github.workflow }}-${{ github.event.number || github.sha }}
cancel-in-progress: true
jobs:
test_pull_request:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v6
with:
node-version-file: '.nvmrc'
cache: 'yarn'
cache-dependency-path: '**/yarn.lock'
- name: Install dependencies
run: yarn
- name: Run build
run: npm run build
- name: Run tests
run: npm test

3
.gitignore vendored
View File

@ -129,5 +129,4 @@ dist
.yarn/install-state.gz
.pnp.*
.DS_Store
next-env.d.ts
.DS_Store

1
.nvmrc
View File

@ -1 +0,0 @@
24.11.0

View File

@ -1,2 +1 @@
.next
next-env.d.ts
.next

1
.prettierrc.cjs Normal file
View File

@ -0,0 +1 @@
module.exports = require('eslint-config-mantine/.prettierrc.js');

View File

@ -1,35 +0,0 @@
/** @type {import("@ianvs/prettier-plugin-sort-imports").PrettierConfig} */
const config = {
printWidth: 100,
singleQuote: true,
trailingComma: 'es5',
plugins: ['@ianvs/prettier-plugin-sort-imports'],
importOrder: [
'.*styles.css$',
'',
'dayjs',
'^react$',
'^next$',
'^next/.*$',
'<BUILTIN_MODULES>',
'<THIRD_PARTY_MODULES>',
'^@mantine/(.*)$',
'^@mantinex/(.*)$',
'^@mantine-tests/(.*)$',
'^@docs/(.*)$',
'^@/.*$',
'^../(?!.*.css$).*$',
'^./(?!.*.css$).*$',
'\\.css$',
],
overrides: [
{
files: '*.mdx',
options: {
printWidth: 70,
},
},
],
};
export default config;

View File

@ -1,16 +1,16 @@
import type { StorybookConfig } from '@storybook/nextjs';
const config: StorybookConfig = {
core: {
disableWhatsNewNotifications: true,
disableTelemetry: true,
enableCrashReports: false,
},
stories: ['../components/**/*.(stories|story).@(js|jsx|ts|tsx)'],
addons: ['@storybook/addon-themes'],
addons: [
'@storybook/addon-essentials',
'storybook-dark-mode',
'@storybook/addon-styling-webpack',
],
framework: {
name: '@storybook/nextjs',
options: {},
},
};
export default config;

View File

@ -1,41 +1,25 @@
import '@mantine/core/styles.css';
import { ColorSchemeScript, MantineProvider } from '@mantine/core';
import React, { useEffect } from 'react';
import { addons } from '@storybook/preview-api';
import { DARK_MODE_EVENT_NAME } from 'storybook-dark-mode';
import { MantineProvider, useMantineColorScheme } from '@mantine/core';
import { theme } from '../theme';
export const parameters = {
layout: 'fullscreen',
options: {
showPanel: false,
// @ts-expect-error storybook throws build error for (a: any, b: any)
storySort: (a, b) => a.title.localeCompare(b.title, undefined, { numeric: true }),
},
backgrounds: { disable: true },
};
const channel = addons.getChannel();
export const globalTypes = {
theme: {
name: 'Theme',
description: 'Mantine color scheme',
defaultValue: 'light',
toolbar: {
icon: 'mirror',
items: [
{ value: 'light', title: 'Light' },
{ value: 'dark', title: 'Dark' },
],
},
},
};
function ColorSchemeWrapper({ children }: { children: React.ReactNode }) {
const { setColorScheme } = useMantineColorScheme();
const handleColorScheme = (value: boolean) => setColorScheme(value ? 'dark' : 'light');
useEffect(() => {
channel.on(DARK_MODE_EVENT_NAME, handleColorScheme);
return () => channel.off(DARK_MODE_EVENT_NAME, handleColorScheme);
}, [channel]);
return <>{children}</>;
}
export const decorators = [
(renderStory: any, context: any) => {
const scheme = (context.globals.theme || 'light') as 'light' | 'dark';
return (
<MantineProvider theme={theme} forceColorScheme={scheme}>
<ColorSchemeScript />
{renderStory()}
</MantineProvider>
);
},
(renderStory: any) => <ColorSchemeWrapper>{renderStory()}</ColorSchemeWrapper>,
(renderStory: any) => <MantineProvider theme={theme}>{renderStory()}</MantineProvider>,
];

893
.yarn/releases/yarn-4.0.1.cjs vendored Executable file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,3 +1,2 @@
nodeLinker: node-modules
yarnPath: .yarn/releases/yarn-4.11.0.cjs
yarnPath: .yarn/releases/yarn-4.0.1.cjs

View File

@ -1,7 +1,6 @@
import '@mantine/core/styles.css';
import React from 'react';
import { ColorSchemeScript, mantineHtmlProps, MantineProvider } from '@mantine/core';
import { MantineProvider, ColorSchemeScript } from '@mantine/core';
import { theme } from '../theme';
export const metadata = {
@ -11,7 +10,7 @@ export const metadata = {
export default function RootLayout({ children }: { children: any }) {
return (
<html lang="en" {...mantineHtmlProps}>
<html lang="en">
<head>
<ColorSchemeScript />
<link rel="shortcut icon" href="/favicon.svg" />

View File

@ -1,5 +1,5 @@
import { ColorSchemeToggle } from '../components/ColorSchemeToggle/ColorSchemeToggle';
import { Welcome } from '../components/Welcome/Welcome';
import { ColorSchemeToggle } from '../components/ColorSchemeToggle/ColorSchemeToggle';
export default function HomePage() {
return (

View File

@ -1,7 +1,9 @@
import { render, screen } from '@/test-utils';
import { render, screen, tests } from '@/test-utils';
import { Welcome } from './Welcome';
describe('Welcome component', () => {
tests.itSupportsClassName({ component: Welcome, props: {} });
it('has correct Next.js theming section link', () => {
render(<Welcome />);
expect(screen.getByText('this guide')).toHaveAttribute(

View File

@ -1,9 +1,9 @@
import { Anchor, Text, Title } from '@mantine/core';
import { Title, Text, Anchor } from '@mantine/core';
import classes from './Welcome.module.css';
export function Welcome() {
export function Welcome(props: React.ComponentPropsWithoutRef<'div'>) {
return (
<>
<div {...props}>
<Title className={classes.title} ta="center" mt={100}>
Welcome to{' '}
<Text inherit variant="gradient" component="span" gradient={{ from: 'pink', to: 'yellow' }}>
@ -18,6 +18,6 @@ export function Welcome() {
</Anchor>
. To get started edit page.tsx file.
</Text>
</>
</div>
);
}

View File

@ -1,22 +0,0 @@
import mantine from 'eslint-config-mantine';
import { defineConfig } from 'eslint/config';
import tseslint from 'typescript-eslint';
// @ts-check
export default defineConfig(
tseslint.configs.recommended,
...mantine,
{ ignores: ['**/*.{mjs,cjs,js,d.ts,d.mts}', '.next'] },
{
files: ['**/*.story.tsx'],
rules: { 'no-console': 'off' },
},
{
languageOptions: {
parserOptions: {
tsconfigRootDir: process.cwd(),
project: ['./tsconfig.json'],
},
},
}
);

View File

@ -2,7 +2,6 @@ require('@testing-library/jest-dom');
const { getComputedStyle } = window;
window.getComputedStyle = (elt) => getComputedStyle(elt);
window.HTMLElement.prototype.scrollIntoView = () => {};
Object.defineProperty(window, 'matchMedia', {
writable: true,

5
next-env.d.ts vendored Normal file
View File

@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.

View File

@ -6,6 +6,9 @@ const withBundleAnalyzer = bundleAnalyzer({
export default withBundleAnalyzer({
reactStrictMode: false,
eslint: {
ignoreDuringBuilds: true,
},
experimental: {
optimizePackageImports: ['@mantine/core', '@mantine/hooks'],
},

View File

@ -8,60 +8,67 @@
"analyze": "ANALYZE=true next build",
"start": "next start",
"typecheck": "tsc --noEmit",
"lint": "npm run eslint && npm run stylelint",
"eslint": "eslint .",
"stylelint": "stylelint '**/*.css' --cache",
"lint": "next lint && npm run lint:stylelint",
"lint:stylelint": "stylelint '**/*.css' --cache",
"jest": "jest",
"jest:watch": "jest --watch",
"prettier:check": "prettier --check \"**/*.{ts,tsx}\"",
"prettier:write": "prettier --write \"**/*.{ts,tsx}\"",
"test": "npx next typegen && npm run prettier:check && npm run lint && npm run typecheck && npm run jest",
"test": "npm run prettier:check && npm run lint && npm run typecheck && npm run jest",
"storybook": "storybook dev -p 6006",
"storybook:build": "storybook build"
},
"dependencies": {
"@mantine/core": "8.3.7",
"@mantine/hooks": "8.3.7",
"@next/bundle-analyzer": "^16.0.0",
"@tabler/icons-react": "^3.35.0",
"next": "16.0.1",
"react": "19.2.0",
"react-dom": "19.2.0"
"@mantine/core": "7.2.2",
"@mantine/hooks": "7.2.2",
"@next/bundle-analyzer": "^14.0.1",
"@tabler/icons-react": "^2.40.0",
"next": "14.0.1",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"@babel/core": "^7.28.4",
"@eslint/eslintrc": "^3",
"@eslint/js": "^9.37.0",
"@ianvs/prettier-plugin-sort-imports": "^4.7.0",
"@storybook/addon-themes": "^10.0.0",
"@storybook/nextjs": "^10.0.0",
"@storybook/react": "^10.0.0",
"@testing-library/dom": "^10.4.1",
"@testing-library/jest-dom": "^6.9.1",
"@testing-library/react": "^16.3.0",
"@testing-library/user-event": "^14.6.1",
"@types/eslint-plugin-jsx-a11y": "^6",
"@types/jest": "^30.0.0",
"@types/node": "^24.7.1",
"@types/react": "19.2.2",
"babel-loader": "^10.0.0",
"eslint": "^9.37.0",
"eslint-config-mantine": "^4.0.3",
"eslint-config-next": "16.0.1",
"eslint-plugin-jsx-a11y": "^6.10.2",
"eslint-plugin-react": "^7.37.5",
"jest": "^30.2.0",
"jest-environment-jsdom": "^30.2.0",
"postcss": "^8.5.6",
"postcss-preset-mantine": "1.18.0",
"@babel/core": "^7.23.2",
"@mantine-tests/core": "^1.0.1",
"@next/eslint-plugin-next": "^14.0.1",
"@storybook/addon-essentials": "^7.5.2",
"@storybook/addon-styling-webpack": "^0.0.5",
"@storybook/blocks": "^7.5.2",
"@storybook/nextjs": "^7.5.2",
"@storybook/react": "^7.5.2",
"@testing-library/dom": "^9.3.3",
"@testing-library/jest-dom": "^6.1.4",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.5.1",
"@types/jest": "^29.5.7",
"@types/node": "^20.8.10",
"@types/react": "18.2.34",
"@typescript-eslint/eslint-plugin": "^6.9.1",
"@typescript-eslint/parser": "^6.9.1",
"babel-loader": "^9.1.3",
"eslint": "^8.53.0",
"eslint-config-airbnb": "19.0.4",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-config-mantine": "3.0.0",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-jest": "^27.6.0",
"eslint-plugin-jsx-a11y": "^6.8.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-testing-library": "^6.1.0",
"jest": "^29.7.0",
"jest-axe": "^8.0.0",
"jest-environment-jsdom": "^29.7.0",
"postcss": "^8.4.31",
"postcss-preset-mantine": "1.11.0",
"postcss-simple-vars": "^7.0.1",
"prettier": "^3.6.2",
"storybook": "^10.0.0",
"stylelint": "^16.25.0",
"stylelint-config-standard-scss": "^16.0.0",
"ts-jest": "^29.4.4",
"typescript": "5.9.3",
"typescript-eslint": "^8.46.0"
"prettier": "^3.0.3",
"storybook": "^7.5.2",
"storybook-dark-mode": "^3.0.1",
"stylelint": "^15.11.0",
"stylelint-config-standard-scss": "^11.1.0",
"ts-jest": "^29.1.1",
"typescript": "5.2.2"
},
"packageManager": "yarn@4.11.0"
"packageManager": "yarn@4.0.1"
}

View File

@ -1,13 +0,0 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"schedule": ["before 5am on sunday"],
"groupName": "all dependencies",
"packageRules": [
{
"matchPackagePatterns": ["*"],
"groupName": "all dependencies"
}
],
"prHourlyLimit": 0,
"prConcurrentLimit": 0
}

View File

@ -1,5 +1,6 @@
import userEvent from '@testing-library/user-event';
export { tests } from '@mantine-tests/core';
export * from '@testing-library/react';
export { render } from './render';
export { userEvent };

View File

@ -5,9 +5,7 @@ import { theme } from '../theme';
export function render(ui: React.ReactNode) {
return testingLibraryRender(<>{ui}</>, {
wrapper: ({ children }: { children: React.ReactNode }) => (
<MantineProvider theme={theme} env="test">
{children}
</MantineProvider>
<MantineProvider theme={theme}>{children}</MantineProvider>
),
});
}

View File

@ -10,28 +10,16 @@
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"jsx": "preserve",
"incremental": true,
"paths": {
"@/*": ["./*"]
},
"plugins": [
{
"name": "next"
}
]
"plugins": [{ "name": "next" }]
},
"include": [
"**/*.ts",
"**/*.tsx",
".storybook/main.ts",
".storybook/preview.tsx",
"next-env.d.ts",
".next/types/**/*.ts",
".next/dev/types/**/*.ts"
],
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}

15775
yarn.lock

File diff suppressed because it is too large Load Diff