Skip to content

Commit

Permalink
Merge pull request #2094 from dxc-technology/gomezivann/more-updates
Browse files Browse the repository at this point in the history
More Halstack updates before 14th
  • Loading branch information
Mil4n0r authored Sep 24, 2024
2 parents 5df2a5e + 899ad44 commit ab373ef
Show file tree
Hide file tree
Showing 9 changed files with 216 additions and 85 deletions.
21 changes: 21 additions & 0 deletions apps/website/pages/components/image/usage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Head from "next/head";
import type { ReactElement } from "react";
import ImagePageLayout from "../../../screens/components/image/ImagePageLayout";
import ImageUsagePage from "../../../screens/components/image/usage/ImageUsagePage";

const Usage = () => {
return (
<>
<Head>
<title>Image Usage — Halstack Design System</title>
</Head>
<ImageUsagePage></ImageUsagePage>
</>
);
};

Usage.getLayout = function getLayout(page: ReactElement) {
return <ImagePageLayout>{page}</ImagePageLayout>;
};

export default Usage;
25 changes: 11 additions & 14 deletions apps/website/screens/common/MainContent.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
import { useToast } from "@dxc-technology/halstack-react";
import { ReactNode, useMemo, useState, useEffect } from "react";
import { ReactNode, useState, useEffect } from "react";
import styled from "styled-components";
import { responsiveSizes } from "./variables";

const MainContainer = styled.div`
margin: 80px 0;
margin: 80px auto;
max-width: 1124px;
margin-inline: max(5%, 50% - 1124px/2);
padding: 0 5%;
@media (max-width: ${responsiveSizes.laptop}px) {
margin: 80px 32px;
}
`;

const pathVersion =
process.env.NEXT_PUBLIC_SITE_VERSION === "next" || process.env.NODE_ENV === "development"
? 0
: parseInt(process.env.NEXT_PUBLIC_SITE_VERSION?.split(".")[0], 10);

const MainContent = ({ children }: { children: ReactNode }) => {
const toast = useToast();
const pathVersion = useMemo(
() =>
process.env.NEXT_PUBLIC_SITE_VERSION === "next" || process.env.NODE_ENV === "development"
? 0
: parseInt(process.env.NEXT_PUBLIC_SITE_VERSION?.split(".")[0], 10),

[]
);
const [latestRelease, setLatestRelease] = useState<number>(null);
const [latestRelease, setLatestRelease] = useState<number | null>(null);

useEffect(() => {
(async () => {
Expand All @@ -39,7 +36,7 @@ const MainContent = ({ children }: { children: ReactNode }) => {
}, []);

useEffect(() => {
if (latestRelease > pathVersion) {
if (pathVersion && latestRelease && latestRelease > pathVersion) {
toast.info({
message: `Halstack ${latestRelease} is now available!`,
action: {
Expand All @@ -54,7 +51,7 @@ const MainContent = ({ children }: { children: ReactNode }) => {
},
});
}
}, [latestRelease, pathVersion, toast]);
}, [latestRelease, toast]);

return <MainContainer>{children}</MainContainer>;
};
Expand Down
4 changes: 2 additions & 2 deletions apps/website/screens/common/componentsList.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
{
"label": "Container",
"path": "/components/container",
"status": "new"
"status": "stable"
},
{
"label": "Contextual Menu",
Expand Down Expand Up @@ -63,7 +63,7 @@
{ "label": "Grid", "path": "/components/grid", "status": "stable" },
{ "label": "Header", "path": "/components/header", "status": "stable" },
{ "label": "Heading", "path": "/components/heading", "status": "stable" },
{ "label": "Image", "path": "/components/image", "status": "experimental" },
{ "label": "Image", "path": "/components/image", "status": "stable" },
{ "label": "Inset", "path": "/components/inset", "status": "stable" },
{ "label": "Link", "path": "/components/link", "status": "stable" },
{ "label": "Nav Tabs", "path": "/components/nav-tabs", "status": "stable" },
Expand Down
21 changes: 21 additions & 0 deletions apps/website/screens/components/flex/usage/FlexUsagePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@ import QuickNavContainer from "@/common/QuickNavContainer";
import QuickNavContainerLayout from "@/common/QuickNavContainerLayout";

const sections = [
{
title: "Overview",
content: (
<>
<DxcParagraph>
The Flex component is designed to provide a more efficient way to organize, align, and distribute space among
items within a container, even when their size is unknown or dynamic (hence the term 'flex').
</DxcParagraph>
<DxcParagraph>
By leveraging the capabilities of the Flex component, developers can create more flexible and responsive
layouts that adapt to different screen sizes and device types. This powerful tool enables the creation of
complex structures that can be easily adjusted to accommodate various content types and user interactions.
</DxcParagraph>
<DxcParagraph>
In the sections that follow, we'll explore the core concepts and best practices for using the Flex component.
By understanding these principles, you can optimize the layout of your application, enhance the user experience,
and create more engaging and visually appealing interfaces.
</DxcParagraph>
</>
),
},
{
title: "Axes",
content: (
Expand Down
5 changes: 4 additions & 1 deletion apps/website/screens/components/image/ImagePageLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import TabsPageHeading from "@/common/TabsPageLayout";
import ComponentHeading from "@/common/ComponentHeading";

const ImagePageHeading = ({ children }: { children: React.ReactNode }) => {
const tabs = [{ label: "Code", path: "/components/image" }];
const tabs = [
{ label: "Code", path: "/components/image" },
{ label: "Usage", path: "/components/image/usage" },
];

return (
<DxcFlex direction="column" gap="3rem">
Expand Down
156 changes: 156 additions & 0 deletions apps/website/screens/components/image/usage/ImageUsagePage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
import { DxcImage, DxcParagraph, DxcFlex, DxcBulletedList } from "@dxc-technology/halstack-react";
import Code from "@/common/Code";
import DocFooter from "@/common/DocFooter";
import QuickNavContainer from "@/common/QuickNavContainer";
import QuickNavContainerLayout from "@/common/QuickNavContainerLayout";

const sections = [
{
title: "Overview",
content: (
<>
<DxcParagraph>
The Image component serves as a versatile tool for efficiently loading and displaying visual content across
diverse contexts within your application. This powerful component is designed to optimize performance while
enhancing the overall user experience. By leveraging its capabilities, developers can seamlessly integrate
images into their projects, ensuring smooth rendering and responsive behavior.
</DxcParagraph>
<DxcParagraph>
To maximize the potential of the Image component and create visually appealing, high-performing applications,
it's crucial to adhere to certain best practices and usage guidelines. These recommendations encompass various
aspects of image implementation, from technical considerations to user-centric design principles. By following
these guidelines, you can ensure that your images not only load quickly and efficiently but also contribute
positively to the user's interaction with your application.
</DxcParagraph>
<DxcParagraph>
In the sections that follow, we'll delve into a comprehensive set of best practices and usage guidelines.
These insights will help you optimize performance, enhance accessibility, and create a more engaging visual
experience for your users across different devices and contexts.
</DxcParagraph>
</>
),
},
{
title: "Accessibility",
content: (
<>
<DxcParagraph>
The Image component should always include an <Code>alt</Code> property to describe the content of the image.
This is important for users who rely on screen readers to understand the content of the page. The alt text
should be a short description of the image content.
</DxcParagraph>
<DxcParagraph>
If an image is purely decorative, use an empty value (<Code>alt=""</Code>) to indicate this to screen readers,
preventing unnecessary noise. Also, include captions when the image is an integral part of the content,
providing users with additional context.
</DxcParagraph>
</>
),
},
{
title: "Aspect ratio and cropping",
content: (
<DxcBulletedList>
<DxcBulletedList.Item>
<strong>Preserve aspect ratio.</strong> The aspect ratio of an image should generally be preserved, unless
explicitly specified otherwise by the design.
</DxcBulletedList.Item>
<DxcBulletedList.Item>
<strong>Avoid distortion.</strong> When resizing images, avoid stretching or squashing them to prevent
distortion. Instead, use <Code>object-fit</Code> to set how the image is displayed or control the dimensions
through the container.
</DxcBulletedList.Item>
<DxcBulletedList.Item>
<strong>Thumbnails and zoom.</strong> When displaying thumbnails or zoomed images, ensure that the image is
cropped appropriately to focus on the most relevant content.
</DxcBulletedList.Item>
</DxcBulletedList>
),
},
{
title: "Considerations for background images",
content: (
<DxcBulletedList>
<DxcBulletedList.Item>
<strong>Image as content vs. background.</strong> If the image is essential content, use the Image component.
For decorative backgrounds, consider using CSS background images to keep content and design separate.
</DxcBulletedList.Item>
<DxcBulletedList.Item>
<strong>Contrast and readability.</strong> Ensure sufficient contrast between background images and overlaid
text. This may require applying filters or overlays to the image.
</DxcBulletedList.Item>
</DxcBulletedList>
),
},
{
title: "Responsiveness",
content: (
<DxcParagraph>
An image should always adapt fluidly to the size of its container, ensuring that it maintains its aspect ratio
unless otherwise specified. To achieve this, it's important to define the width and height properties to ensure
images are loaded with known dimensions, which helps maintain layout stability and reduces cumulative layout
shifts. When designing for multiple devices, leveraging responsive image techniques, such as the{" "}
<Code>srcset</Code> and
<Code>sizes</Code> props, ensures that the appropriate resolution is served based on the user's screen size and
the layout's space allocation. This not only improves performance but also optimizes the experience across
different viewports.
</DxcParagraph>
),
},
{
title: "Best practices",
content: (
<DxcBulletedList>
<DxcBulletedList.Item>
<strong>Use high-quality images.</strong> Always use high-resolution images to deliver a crisp and clear
display, especially on high-density (retina) screens. This ensures a professional look and prevents
pixelation.
</DxcBulletedList.Item>
<DxcBulletedList.Item>
<strong>Optimize images.</strong> Compress and optimize images for the web to minimize file sizes. Reducing
load times and bandwidth consumption is crucial for performance, especially on mobile devices.
</DxcBulletedList.Item>
<DxcBulletedList.Item>
<strong>Leverage modern formats.</strong> Whenever possible, use newer image formats like WebP for improved
compression without sacrificing quality. Be sure to provide fallback formats for browsers that don't support
them.
</DxcBulletedList.Item>
<DxcBulletedList.Item>
<strong>Allow lazy loading.</strong> Implement lazy loading (<Code>loading="lazy"</Code>) for images that
appear later on the page (below the fold). This helps speed up initial page loads and improve overall
performance.
</DxcBulletedList.Item>
<DxcBulletedList.Item>
<strong>Use responsive image techniques.</strong> Make use of <Code>srcset</Code> and <Code>sizes</Code> props
to serve images that adapt to different screen resolutions and sizes, ensuring the best display quality across
devices.
</DxcBulletedList.Item>
<DxcBulletedList.Item>
<strong>Avoid using images for text content.</strong> Text embedded within images reduces accessibility and
harms SEO. Always use HTML text to ensure readability by screen readers and search engines.
</DxcBulletedList.Item>
<DxcBulletedList.Item>
<strong>Limit decorative images.</strong> Avoid overloading pages with unnecessary decorative images. This not
only reduces performance but can also distract users from the main content.
</DxcBulletedList.Item>
<DxcBulletedList.Item>
<strong>Avoid images for icons.</strong> Use scalable vector graphics (SVGs) instead of images for icons. SVGs
offer better performance, scalability, and accessibility across various screen sizes.
</DxcBulletedList.Item>
</DxcBulletedList>
),
},
];

const ImageUsagePage = () => {
return (
<DxcFlex direction="column" gap="4rem">
<QuickNavContainerLayout>
<QuickNavContainer sections={sections} startHeadingLevel={2}></QuickNavContainer>
</QuickNavContainerLayout>
<DocFooter githubLink="https://github.com/dxc-technology/halstack-react/blob/master/website/screens/components/image/usage/ImageUsagePage.tsx" />
</DxcFlex>
);
};

export default ImageUsagePage;
2 changes: 0 additions & 2 deletions apps/website/screens/components/tabs/usage/TabsUsagePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import QuickNavContainer from "@/common/QuickNavContainer";
import QuickNavContainerLayout from "@/common/QuickNavContainerLayout";
import Figure from "@/common/Figure";
import DocFooter from "@/common/DocFooter";
import tabsUsage from "./examples/usage";
import defaultUsage from "./examples/default";
import scrollableUsage from "./examples/scrollable";
import contentUsageTabImage from "./images/tabs_content.png";
Expand All @@ -27,7 +26,6 @@ const sections = [
Tabs organize and allow navigation between groups of content that are related and at the same level of
hierarchy.
</DxcParagraph>
<Example example={tabsUsage}></Example>
</>
),
},
Expand Down
65 changes: 0 additions & 65 deletions apps/website/screens/components/tabs/usage/examples/usage.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/lib/src/link/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { LinkProps } from "./types";

const LinkContent = memo(
({ iconPosition, icon, inheritColor, children }: LinkProps): JSX.Element => (
<LinkContainer inheritColor>
<LinkContainer inheritColor={inheritColor}>
{iconPosition === "after" && children}
{icon && (
<LinkIconContainer iconPosition={iconPosition}>
Expand Down

0 comments on commit ab373ef

Please sign in to comment.