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

[DSDK 175] Add LedgerHQ UI library #8

Merged
merged 8 commits into from
Jan 30, 2024
Merged
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
2 changes: 1 addition & 1 deletion apps/sample/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
extends: ["next/core-web-vitals", "@ledgerhq/dsdk"],
extends: ["next", "@ledgerhq/dsdk"],
parserOptions: {
project: true,
tsconfigRootDir: __dirname,
Expand Down
10 changes: 8 additions & 2 deletions apps/sample/next.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
/** @type {import('next').NextConfig} */
const nextConfig = {}

module.exports = nextConfig
const nextConfig = {
reactStrictMode: true,
compiler: {
styledComponents: true,
},
};

module.exports = nextConfig;
13 changes: 8 additions & 5 deletions apps/sample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@
"lint": "next lint"
},
"dependencies": {
"@ledgerhq/react-ui": "^0.14.13",
"next": "14.0.4",
"react": "^18",
"react-dom": "^18",
"next": "14.0.4"
"styled-components": "^5.3.11"
},
"devDependencies": {
"@ledgerhq/eslint-config-dsdk": "workspace:*",
"@ledgerhq/tsconfig-dsdk": "workspace:*",
"@types/react": "^18",
"@types/styled-components": "^5.1.25",
"autoprefixer": "^10.0.1",
"postcss": "^8",
"tailwindcss": "^3.3.0",
"eslint-config-next": "14.0.4",
"@ledgerhq/tsconfig-dsdk": "workspace:*",
"@ledgerhq/eslint-config-dsdk": "workspace:*"
"postcss": "^8"
}
}
3 changes: 1 addition & 2 deletions apps/sample/postcss.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
};
Binary file removed apps/sample/src/app/favicon.ico
Binary file not shown.
27 changes: 0 additions & 27 deletions apps/sample/src/app/globals.css

This file was deleted.

22 changes: 0 additions & 22 deletions apps/sample/src/app/layout.tsx

This file was deleted.

113 changes: 0 additions & 113 deletions apps/sample/src/app/page.tsx

This file was deleted.

30 changes: 30 additions & 0 deletions apps/sample/src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* _app.tsx
*
* This is a special Next.js file used to wrap the entire application and provide a common
* layout or functionality across all pages. It allows you to maintain state, apply global
* styles, and handle other aspects that should persist across different pages.
*
* The `App` component in this file is initialized once for the entire application and is
* used to customize the rendering of pages. For more information, refer to the Next.js
* documentation on customizing the App component:
* https://nextjs.org/docs/advanced-features/custom-app
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Great, thank you for the added doc ;)


import { CustomThemeProvider } from "@/providers/theme";
import { GlobalStyle } from "@/styles/globalstyles";
import type { AppProps } from "next/app";
import { Inter } from "next/font/google";

const inter = Inter({ subsets: ["latin"] });

export default function App({ Component, pageProps }: AppProps) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we only use naming exports ?
An eslint rule could be useful for this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For this file, next require a default import. But I agree we should use naming exports when possible.

Copy link
Member

Choose a reason for hiding this comment

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

Why use only named exports @jdabbech-ledger ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Named exports are more restrictive as they require you to use a specific identifier when importing. Default exports are more flexible, you can use any name during import but may lead to inconsistencies in the codebase.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @aussedatlo on this point, moreover the IDEs follow more easily the import with naming exports in general

return (
<main className={inter.className}>
<CustomThemeProvider>
<GlobalStyle />
<Component {...pageProps} />
</CustomThemeProvider>
</main>
);
}
41 changes: 41 additions & 0 deletions apps/sample/src/pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* _document.tsx
*
* This is a special Next.js file used to create a custom document layout. It allows you
* to enhance and optimize the server-side rendering of your application by customizing
* the HTML document structure. This file is crucial for implementing global styles, meta
* tags, and other layout-related configurations that should be applied on the server side.
*
* Keep in mind that changes made in this file affect the entire application's HTML structure,
* so use it judiciously. For more information, refer to the Next.js documentation on customizing
* the document: https://nextjs.org/docs/advanced-features/custom-document
*/

import type { DocumentContext, DocumentInitialProps } from "next/document";
import Document from "next/document";
import { ServerStyleSheet } from "styled-components";

export default class MyDocument extends Document {
aussedatlo marked this conversation as resolved.
Show resolved Hide resolved
static async getInitialProps(
ctx: DocumentContext
): Promise<DocumentInitialProps> {
const sheet = new ServerStyleSheet();
const originalRenderPage = ctx.renderPage;

try {
ctx.renderPage = () =>
originalRenderPage({
enhanceApp: (App) => (props) =>
sheet.collectStyles(<App {...props} />),
});

const initialProps = await Document.getInitialProps(ctx);
return {
...initialProps,
styles: [initialProps.styles, sheet.getStyleElement()],
};
} finally {
sheet.seal();
}
}
}
18 changes: 18 additions & 0 deletions apps/sample/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"use client";
import React from "react";
import { Box } from "@ledgerhq/react-ui/index";
import styled, { DefaultTheme } from "styled-components";

const MainContainer = styled(Box)`
width: 100%;
height: 100%;
background-color: ${({ theme }: { theme: DefaultTheme }) =>
theme.colors.background.main};
color: ${({ theme }: { theme: DefaultTheme }) => theme.colors.neutral.c90};
`;

const Home: React.FC = () => {
return <MainContainer>Test</MainContainer>;
};

export default Home;
27 changes: 27 additions & 0 deletions apps/sample/src/providers/theme.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React, { useMemo } from "react";
import { defaultTheme, palettes } from "@ledgerhq/react-ui/styles/index";
import { ThemeProvider } from "styled-components";

interface CustomThemeProviderProps {
children: React.ReactNode;
}

export const CustomThemeProvider: React.FC<CustomThemeProviderProps> = ({
children,
}) => {
const selectedPalettes: "dark" | "light" = "dark";

const theme = useMemo(
() => ({
...defaultTheme,
theme: selectedPalettes,
colors: {
...defaultTheme.colors,
...palettes[selectedPalettes],
},
}),
[]
);

return <ThemeProvider theme={theme}>{children}</ThemeProvider>;
};
14 changes: 14 additions & 0 deletions apps/sample/src/styles/globalstyles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createGlobalStyle } from "styled-components";

export const GlobalStyle = createGlobalStyle`
html,
body,
#__next,
main {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
background-color: #000000;
}
`;
20 changes: 0 additions & 20 deletions apps/sample/tailwind.config.ts

This file was deleted.

5 changes: 3 additions & 2 deletions apps/sample/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
],
"paths": {
"@/*": ["./src/*"]
}
},
"strictNullChecks": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"include": ["**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
Loading
Loading