Skip to content

Commit

Permalink
feat(fluid-text-input): adds skeleton variant (#12151)
Browse files Browse the repository at this point in the history
* feat(fluid-text-input): adds skeleton variant

* chore(fluid-text-input): update snapshots
  • Loading branch information
aledavila committed Oct 5, 2022
1 parent f2ce743 commit 5e069c8
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 1 deletion.
7 changes: 7 additions & 0 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9276,6 +9276,13 @@ Map {
},
},
},
"unstable__FluidTextInputSkeleton" => Object {
"propTypes": Object {
"className": Object {
"type": "string",
},
},
},
"unstable_useContextMenu" => Object {},
"unstable_useFeatureFlag" => Object {},
"unstable_useFeatureFlags" => Object {},
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/__tests__/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ describe('Carbon Components React', () => {
"unstable_TextDirection",
"unstable__FluidTextArea",
"unstable__FluidTextInput",
"unstable__FluidTextInputSkeleton",
"unstable_useContextMenu",
"unstable_useFeatureFlag",
"unstable_useFeatureFlags",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright IBM Corp. 2016, 2018
*
* 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 PropTypes from 'prop-types';
import React from 'react';
import classnames from 'classnames';
import { usePrefix } from '../../internal/usePrefix';
import { FormContext } from '../FluidForm/FormContext';

function FluidTextInputSkeleton({ className, ...other }) {
const prefix = usePrefix();

return (
<FormContext.Provider value={{ isFluid: true }}>
<div
className={classnames(
`${prefix}--form-item ${prefix}--text-input--fluid__skeleton`,
className
)}
{...other}>
<span className={`${prefix}--label ${prefix}--skeleton`} />
<div className={`${prefix}--skeleton ${prefix}--text-input`} />
</div>
</FormContext.Provider>
);
}

FluidTextInputSkeleton.propTypes = {
/**
* Specify an optional className to be applied to the outer FluidForm wrapper
*/
className: PropTypes.string,
};

export default FluidTextInputSkeleton;
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import React from 'react';
import FluidTextInput from '../FluidTextInput';
import FluidTextInputSkeleton from './FluidTextInput.Skeleton';
import {
ToggletipLabel,
Toggletip,
Expand Down Expand Up @@ -58,6 +59,16 @@ export const DefaultWithTooltip = () => (
<FluidTextInput labelText={ToggleTip} placeholder="Placeholder text" />
);

export const Skeleton = () => (
<div style={{ width: '300px' }}>
<FluidTextInputSkeleton
labelText="Label"
placeholder="Placeholder text"
id="input-1"
/>
</div>
);

export const Playground = (args) => (
<div style={{ width: args.playgroundWidth }}>
<FluidTextInput {...args} />
Expand Down
2 changes: 2 additions & 0 deletions packages/react/src/components/FluidTextInput/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@

export default from './FluidTextInput';
export FluidTextInput from './FluidTextInput';

export { default as FluidTextInputSkeleton } from './FluidTextInput.Skeleton';
5 changes: 4 additions & 1 deletion packages/react/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,10 @@ export {
useFeatureFlag as unstable_useFeatureFlag,
useFeatureFlags as unstable_useFeatureFlags,
} from './components/FeatureFlags';
export { FluidTextInput as unstable__FluidTextInput } from './components/FluidTextInput';
export {
FluidTextInput as unstable__FluidTextInput,
FluidTextInputSkeleton as unstable__FluidTextInputSkeleton,
} from './components/FluidTextInput';
export { FluidTextArea as unstable__FluidTextArea } from './components/FluidTextArea';
export { Heading, Section } from './components/Heading';
export { IconButton } from './components/IconButton';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,25 @@
width: rem(32px);
height: rem(32px);
}

// Skeleton
.#{$prefix}--text-input--fluid__skeleton {
position: relative;
height: 100%;
padding: $spacing-05;
border-bottom: 1px solid $skeleton-element;
background: $skeleton-background;
}

.#{$prefix}--text-input--fluid__skeleton .#{$prefix}--skeleton {
height: 0.5rem;
}

.#{$prefix}--text-input--fluid__skeleton .#{$prefix}--label {
margin-bottom: $spacing-04;
}

.#{$prefix}--text-input--fluid__skeleton .#{$prefix}--text-input {
width: 80%;
}
}

0 comments on commit 5e069c8

Please sign in to comment.