Skip to content

Commit

Permalink
feat: add ai label examples
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewgallo committed Nov 7, 2024
1 parent 4cdbca5 commit a66c4d5
Show file tree
Hide file tree
Showing 22 changed files with 3,170 additions and 0 deletions.
2 changes: 2 additions & 0 deletions react/ai-label/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VITE_CODE_SANDBOX_URL_ROOT=https://codesandbox.io/s/github/carbon-design-system/tanstack-carbon/tree/main/react
VITE_STACK_BLITZ_URL_ROOT=https://stackblitz.com/github/carbon-design-system/tanstack-carbon/tree/main/react
24 changes: 24 additions & 0 deletions react/ai-label/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
58 changes: 58 additions & 0 deletions react/ai-label/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and
some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md)
uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc)
uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the
configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:

```js
export default tseslint.config({
languageOptions: {
// other options...
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
},
});
```

- Replace `tseslint.configs.recommended` to
`tseslint.configs.recommendedTypeChecked` or
`tseslint.configs.strictTypeChecked`
- Optionally add `...tseslint.configs.stylisticTypeChecked`
- Install
[eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and
update the config:

```js
// eslint.config.js
import react from 'eslint-plugin-react';

export default tseslint.config({
// Set the react version
settings: { react: { version: '18.3' } },
plugins: {
// Add the react plugin
react,
},
rules: {
// other rules...
// Enable its recommended rules
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,
},
});
```
29 changes: 29 additions & 0 deletions react/ai-label/eslint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import js from '@eslint/js';
import globals from 'globals';
import reactHooks from 'eslint-plugin-react-hooks';
import reactRefresh from 'eslint-plugin-react-refresh';
import tseslint from 'typescript-eslint';

export default tseslint.config(
{ ignores: ['dist'] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
'@typescript-eslint/no-explicit-any': 'off',
},
}
);
13 changes: 13 additions & 0 deletions react/ai-label/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
37 changes: 37 additions & 0 deletions react/ai-label/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "ai-label",
"private": true,
"version": "0.0.0",
"type": "module",
"main": "src/index.ts",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"@carbon/ibm-products": "^2.47.0",
"@carbon/react": "^1.64.1",
"@faker-js/faker": "^8.4.1",
"@tanstack/react-table": "^8.20.1",
"classnames": "^2.5.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"sass": "^1.77.8"
},
"devDependencies": {
"@eslint/js": "^9.9.0",
"@types/node": "^22.5.0",
"@types/react": "^18.3.4",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.1",
"eslint": "^9.9.0",
"eslint-plugin-react-hooks": "^5.1.0-rc.0",
"eslint-plugin-react-refresh": "^0.4.9",
"globals": "^15.9.0",
"typescript": "^5.5.3",
"typescript-eslint": "^8.0.1",
"vite": "^5.4.1"
}
}
1 change: 1 addition & 0 deletions react/ai-label/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
74 changes: 74 additions & 0 deletions react/ai-label/src/App.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
@use '@carbon/styles/scss/theme' as *;
@use '@carbon/styles/scss/spacing' as *;
@use '@carbon/styles/scss/utilities';
@use '@carbon/styles/scss/colors';
@use '@carbon/styles/scss/type';
@use '@carbon/type/scss/font-family';

.page-grid {
margin-top: 4rem;
}

.flex {
display: flex;
align-items: center;
}

.tanstack-example {
padding-bottom: 2rem;
}

// Sorting
.descending-sorting-icon {
transform: rotate(180deg);
transition: transform 200ms;
}

.sortable-button-header {
color: $text-primary;
width: 100%;
padding-inline: 1rem;
max-inline-size: none;

@include type.font-weight('semibold');

&.cds--btn--ghost:hover,
&.cds--btn--ghost:active {
color: $text-primary;
}
}

.sortable-example.cds--data-table th {
padding-inline: 0;
}

.sortable-example {
padding-bottom: 2rem;
}

.ai-label-is-present {
position: relative;
}

.ai-label-is-present .sortable-button-header svg {
position: absolute;
right: 2rem;
}

.ai-label-container {
position: absolute;
top: 0;
bottom: 0;
align-items: center;
right: 0.5rem;
}

.custom-ai-header-wrapper {
display: flex;
}

.cds--data-table thead th.ai-label-is-present .sortable-button-header,
.cds--data-table thead th.ai-label-is-present.ai-column,
td.ai-cell {
@include utilities.ai-table-gradient;
}
Loading

0 comments on commit a66c4d5

Please sign in to comment.