Skip to content

Commit

Permalink
create FieldsetBase component (#2136)
Browse files Browse the repository at this point in the history
  • Loading branch information
mayank99 authored Jul 10, 2024
1 parent a164f99 commit 704e57e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 8 deletions.
10 changes: 10 additions & 0 deletions .changeset/mean-hornets-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@itwin/itwinui-css': major
---

Added a new `iui-fieldset-base` class that removes default `<fieldset>` styles. This class is now required when using `iui-fieldset`.

```diff
- <fieldset class="iui-fieldset">
+ <fieldset class="iui-fieldset-base iui-fieldset">
```
4 changes: 2 additions & 2 deletions apps/css-workshop/src/pages/fieldset.astro
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Icon_ from '../components/Icon.astro';
<hr />

<section id='demo-default'>
<fieldset class='iui-fieldset'>
<fieldset class='iui-fieldset-base iui-fieldset'>
<legend>General settings</legend>

<div class='iui-input-grid' data-iui-label-placement='inline'>
Expand Down Expand Up @@ -76,7 +76,7 @@ import Icon_ from '../components/Icon.astro';

<br />

<fieldset class='iui-fieldset' disabled>
<fieldset class='iui-fieldset-base iui-fieldset' disabled>
<legend>Advanced settings</legend>

<label class='iui-input-grid' data-iui-label-placement='inline'>
Expand Down
8 changes: 6 additions & 2 deletions packages/itwinui-css/src/fieldset/fieldset.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
// Copyright (c) Bentley Systems, Incorporated. All rights reserved.
// See LICENSE.md in the project root for license terms and full copyright notice.
@use '../mixins';

:where(.iui-fieldset-base) {
padding: 0;
margin: 0;
border: none;
}

.iui-fieldset {
@include mixins.iui-reset;
padding: var(--iui-size-s);
border-radius: var(--iui-border-radius-1);
border: 1px solid var(--iui-color-border);
Expand Down
7 changes: 3 additions & 4 deletions packages/itwinui-react/src/core/Fieldset/Fieldset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import * as React from 'react';
import { Box } from '../../utils/index.js';
import { FieldsetBase } from '../../utils/index.js';
import type { PolymorphicForwardRefComponent } from '../../utils/index.js';

import cx from 'classnames';
Expand All @@ -30,8 +30,7 @@ export const Fieldset = React.forwardRef((props, ref) => {
const { children, className, disabled, legend, ...rest } = props;

return (
<Box
as='fieldset'
<FieldsetBase
className={cx('iui-fieldset', className)}
disabled={disabled}
ref={ref}
Expand All @@ -46,6 +45,6 @@ export const Fieldset = React.forwardRef((props, ref) => {
: child,
)
: children}
</Box>
</FieldsetBase>
);
}) as PolymorphicForwardRefComponent<'fieldset', FieldsetProps>;
12 changes: 12 additions & 0 deletions packages/itwinui-react/src/utils/components/FieldsetBase.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import { polymorphic } from '../functions/polymorphic.js';

/**
* Thin wrapper over the `<fieldset>` element that removes its default styles.
*
* @private
*/
export const FieldsetBase = polymorphic.fieldset('iui-fieldset-base');
1 change: 1 addition & 0 deletions packages/itwinui-react/src/utils/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ export * from './ButtonBase.js';
export * from './Portal.js';
export * from './ShadowRoot.js';
export * from './LineClamp.js';
export * from './FieldsetBase.js';

0 comments on commit 704e57e

Please sign in to comment.