Skip to content

Commit

Permalink
ui-kit: support nextjs with vite
Browse files Browse the repository at this point in the history
Signed-off-by: Viktor Login <[email protected]>
  • Loading branch information
batazor committed Dec 2, 2024
1 parent 2152ad6 commit fa6c2c5
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 67 deletions.
4 changes: 2 additions & 2 deletions boundaries/platform/ui-kit/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { StorybookConfig } from '@storybook/react-vite'
import type { StorybookConfig } from '@storybook/experimental-nextjs-vite'

const config: StorybookConfig = {
stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
Expand All @@ -20,7 +20,7 @@ const config: StorybookConfig = {
},

framework: {
name: '@storybook/react-vite',
name: '@storybook/experimental-nextjs-vite',
options: {}
},

Expand Down
2 changes: 1 addition & 1 deletion boundaries/platform/ui-kit/.storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ThemeProvider as ThemeProviderNext } from 'next-themes'
import { LocalizationProvider } from '@mui/x-date-pickers'
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'

// import '../src/theme/styles.css'
import '../src/theme/styles.css'
import { theme } from '../src/theme/theme'

const preview: Preview = {
Expand Down
1 change: 1 addition & 0 deletions boundaries/platform/ui-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@mui/material": "^6.1.9",
"@mui/x-date-pickers": "8.0.0-alpha.2",
"@storybook/builder-vite": "8.5.0-alpha.14",
"@storybook/experimental-nextjs-vite": "8.5.0-alpha.14",
"@tailwindcss/postcss": "4.0.0-beta.4",
"@tailwindcss/typography": "^0.5.15",
"@types/react": "^18.3.12",
Expand Down
80 changes: 80 additions & 0 deletions boundaries/platform/ui-kit/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 38 additions & 38 deletions boundaries/platform/ui-kit/src/page/Sidebar/ActiveLink.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Link, { LinkProps } from 'next/link'
import { usePathname } from 'next/navigation'
// import { usePathname } from 'next/navigation'
// @ts-ignore
import React, { useState, useEffect, ReactElement, Children } from 'react'

Expand All @@ -9,46 +9,46 @@ type ActiveLinkProps = LinkProps & {
}

function ActiveLink({ children, activeClassName, ...props }: ActiveLinkProps) {
const currentPath = usePathname()

const child = Children.only(children)
const childClassName = child.props.className || ''
const [className, setClassName] = useState(childClassName)

useEffect(() => {
// Dynamic route will be matched via props.as
// Static route will be matched via props.href
const linkPathname = new URL(
(props.as || props.href) as string,
location.href,
).pathname

// Using URL().pathname to get rid of query and hash
const activePathname = new URL(currentPath, location.href).pathname

const newClassName =
linkPathname === activePathname
? `${childClassName} ${activeClassName}`.trim()
: childClassName

if (newClassName !== className) {
setClassName(newClassName)
}
}, [
currentPath,
props.as,
props.href,
childClassName,
activeClassName,
setClassName,
className,
])
// const currentPath = usePathname()

// const child = Children.only(children)
// const childClassName = child.props.className || ''
// const [className, setClassName] = useState(childClassName)

// useEffect(() => {
// // Dynamic route will be matched via props.as
// // Static route will be matched via props.href
// const linkPathname = new URL(
// (props.as || props.href) as string,
// location.href,
// ).pathname
//
// // Using URL().pathname to get rid of query and hash
// const activePathname = new URL(currentPath, location.href).pathname
//
// const newClassName =
// linkPathname === activePathname
// ? `${childClassName} ${activeClassName}`.trim()
// : childClassName
//
// if (newClassName !== className) {
// setClassName(newClassName)
// }
// }, [
// currentPath,
// props.as,
// props.href,
// childClassName,
// activeClassName,
// setClassName,
// className,
// ])

return (
<Link {...props}>
{React.cloneElement(child, {
className: className || null,
})}
{/*{React.cloneElement(child, {*/}
{/* className: className || null,*/}
{/*})}*/}
</Link>
)
}
Expand Down
27 changes: 1 addition & 26 deletions boundaries/platform/ui-kit/src/theme/styles.css
Original file line number Diff line number Diff line change
@@ -1,26 +1 @@
/**
* This injects Tailwind's base styles and any base styles registered by
* plugins.
*/
@tailwind base;

/**
* This injects Tailwind's component classes and any component classes
* registered by plugins.
*/
@tailwind components;

/**
* This injects Tailwind's utility classes and any utility classes registered
* by plugins.
*/
@tailwind utilities;

/**
* Use this directive to control where Tailwind injects the hover, focus,
* responsive, dark mode, and other variants of each class.
*
* If omitted, Tailwind will append these classes to the very end of
* your stylesheet by default.
*/
@tailwind variants;
@import "tailwindcss";

0 comments on commit fa6c2c5

Please sign in to comment.