Skip to content
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
7 changes: 7 additions & 0 deletions packages/assets/src/scss/_choice-input-field.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@use 'functions' as *;

.ids-choice-input-field {
display: flex;
align-items: center;
gap: calculateRem(8px);
}
3 changes: 2 additions & 1 deletion packages/assets/src/scss/_choice-input-label.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@use './variables' as *;
@use 'variables' as *;

.ids-choice-input-label {
color: $color-neutral-240;
font-size: $text-font-size-m;
cursor: pointer;
}
3 changes: 3 additions & 0 deletions packages/assets/src/scss/_choice-input.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.ids-choice-input {
line-height: 0;
}
2 changes: 2 additions & 0 deletions packages/assets/src/scss/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
@use 'accordion';
@use 'autosave';
@use 'buttons';
@use 'choice-input';
@use 'choice-input-field';
@use 'choice-input-label';
@use 'expander';
@use 'fonts';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';

import BaseInput from '@ids-internal/partials/BaseInput';
import { createCssClassNames } from '@ibexa/ids-core/helpers/cssClassNames';

import { BaseChoiceInputProps } from './BaseChoiceInput.types';

Expand All @@ -23,6 +24,10 @@ const BaseChoiceInput = ({
title = '',
value = '',
}: BaseChoiceInputProps) => {
const componentClassName = createCssClassNames({
'ids-choice-input': true,
[className]: !!className,
});
const componentOnBlur = (event: React.FocusEvent<HTMLInputElement>) => {
onBlur(event);
};
Expand All @@ -37,7 +42,7 @@ const BaseChoiceInput = ({
};

return (
<div className={className}>
<div className={componentClassName}>
<BaseInput
className={inputClassName}
disabled={disabled}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from 'react';

import type { Meta, StoryObj } from '@storybook/react';

import BaseChoiceInputField from './BaseChoiceInputField';
import { RadioButtonStateful } from '../../../inputs/RadioButton';

const meta: Meta<typeof BaseChoiceInputField> = {
title: 'components/src/base/BaseChoiceInputField',
component: BaseChoiceInputField,
parameters: {
layout: 'centered',
},
tags: ['autodocs', 'foundation', 'base'],
argTypes: {
className: { control: 'text' },
renderInput: { control: false },
},
args: {
id: 'default-radio',
renderInput: () => <RadioButtonStateful checked={false} id="default-radio" name="default-radio" value="default" />,
},
decorators: [
(Story) => {
return (
<form name="default-form">
<Story />
</form>
);
},
],
};

export default meta;

type Story = StoryObj<typeof BaseChoiceInputField>;

export const Default: Story = {
name: 'Default',
args: {
children: 'Lorem Ipsum',
},
};

export const withHTML: Story = {
name: 'With HTML',
args: {
children: (
<>
<b>Lorem</b>&nbsp;<u>Ipsum</u>
</>
),
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from 'react';

import ChoiceInputLabel from '../../../ChoiceInputLabel';
import { createCssClassNames } from '@ibexa/ids-core/helpers/cssClassNames';

import { BaseChoiceInputFieldProps } from './BaseChoiceInputField.types';

const BaseChoiceInputField = ({
children,
className = '',
id,
inputWrapperClassName = '',
labelClassName = '',
renderInput,
}: BaseChoiceInputFieldProps) => {
const componentClassName = createCssClassNames({
'ids-choice-input-field': true,
[className]: true,
});
const componentInputWrapperClassName = createCssClassNames({
'ids-choice-input-field__input-wrapper': true,
[inputWrapperClassName]: true,
});
const componentLabelClassName = createCssClassNames({
'ids-choice-input-field__label': true,
[labelClassName]: true,
});

return (
<div className={componentClassName}>
<div className={componentInputWrapperClassName}>{renderInput()}</div>
<ChoiceInputLabel className={componentLabelClassName} htmlFor={id}>
{children}
</ChoiceInputLabel>
</div>
);
};

export default BaseChoiceInputField;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { BaseComponentAriaAttributes } from '@ids-types/general';

export interface BaseChoiceInputFieldProps extends BaseComponentAriaAttributes {
children: React.ReactNode;
id: string;
inputWrapperClassName?: string;
labelClassName?: string;
renderInput: () => React.ReactNode;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import BaseChoiceInputField from './BaseChoiceInputField';
import { BaseChoiceInputFieldProps } from './BaseChoiceInputField.types';

export default BaseChoiceInputField;
export type { BaseChoiceInputFieldProps };