Skip to content

Commit

Permalink
fix(react): export types for Stack component (#15456)
Browse files Browse the repository at this point in the history
* fix(react): export types for Stack component

Signed-off-by: Onur Özkardeş <onurozkardess@gmail.com>

* refactor(react/stack): move type declarations into main component file

* fix(stack): get spacing definition from layout instead of icons-react

---------

Signed-off-by: Onur Özkardeş <onurozkardess@gmail.com>
Co-authored-by: Onur Özkardeş <onurozkardes@Onurs-MacBook-Pro.local>
Co-authored-by: Andrea N. Cardona <cardona.n.andrea@gmail.com>
  • Loading branch information
3 people committed Mar 19, 2024
1 parent 4042f5f commit 2a7043c
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 29 deletions.
8 changes: 8 additions & 0 deletions .all-contributorsrc
Expand Up @@ -1390,6 +1390,14 @@
]
},
{
"login": "onurozkardes",
"name": "Onur Özkardeş",
"avatar_url": "https://avatars.githubusercontent.com/u/38096930?v=4",
"profile": "https://github.com/onurozkardes",
"contributions": [
"code"
]
},
"login": "mattborghi",
"name": "Matias Borghi",
"avatar_url": "https://avatars.githubusercontent.com/u/11933424?v=4",
Expand Down
23 changes: 23 additions & 0 deletions packages/react/src/components/Stack/HStack.tsx
@@ -0,0 +1,23 @@
/**
* Copyright IBM Corp. 2016, 2023
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';

import { Stack, StackProps } from './Stack';

const HStack = React.forwardRef<React.ReactNode, StackProps>(function HStack(
{ children, ...props },
ref
) {
return (
<Stack {...props} ref={ref} orientation="horizontal">
{children}
</Stack>
);
});

export { HStack };
7 changes: 4 additions & 3 deletions packages/react/src/components/Stack/Stack.tsx
Expand Up @@ -5,10 +5,11 @@
* LICENSE file in the root directory of this source tree.
*/

import { spacing } from '@carbon/layout';
import React from 'react';
import cx from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';
import { spacing } from '@carbon/layout';

import { usePrefix } from '../../internal/usePrefix';

/**
Expand All @@ -21,7 +22,7 @@ const SPACING_STEPS = Array.from({ length: spacing.length - 1 }).map(
}
);

interface StackProps extends React.HTMLAttributes<HTMLElement> {
export interface StackProps extends React.HTMLAttributes<HTMLElement> {
/**
* Provide a custom element type to render as the outermost element in
* the Stack component. By default, this component will render a `div`.
Expand Down
19 changes: 19 additions & 0 deletions packages/react/src/components/Stack/VStack.tsx
@@ -0,0 +1,19 @@
/**
* Copyright IBM Corp. 2016, 2023
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';

import { Stack, StackProps } from './Stack';

const VStack = React.forwardRef<React.ReactNode, StackProps>(function VStack(
props,
ref
) {
return <Stack {...props} ref={ref} orientation="vertical" />;
});

export { VStack };
10 changes: 10 additions & 0 deletions packages/react/src/components/Stack/index.ts
@@ -0,0 +1,10 @@
/**
* Copyright IBM Corp. 2016, 2023
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

export { HStack } from './HStack';
export { VStack } from './VStack';
export { Stack, type StackProps } from './Stack';
26 changes: 0 additions & 26 deletions packages/react/src/components/Stack/index.tsx

This file was deleted.

1 change: 1 addition & 0 deletions packages/react/src/index.ts
Expand Up @@ -76,6 +76,7 @@ export * from './components/SkeletonIcon';
export * from './components/SkeletonPlaceholder';
export * from './components/SkeletonText';
export * from './components/Slider';
export * from './components/Stack';
export * from './components/StructuredList';
export * from './components/Switch';
export * from './components/Tab';
Expand Down

0 comments on commit 2a7043c

Please sign in to comment.