Closed AndrewOCC closed 4 months ago
Latest commit: 75b394ab1a4b30702de72784f33df3336461cc05
The changes in this PR will be included in the next version bump.
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
Closing this PR; after discussion with @kylorhall-atlassian we found that although this feature is desired, a more robust implementation through a separate API may be necessary. In addition, there are implications for other parts of the compiled API works - for example, how do you support tight types in CSSMap when the types are different per-component?
For example, how do you support tight types in CSSMap when the types are different per-component?
Yeah, I think this change is required for us to move the needle in the future—but what does this look like? How do we allow color: Text | IconFill
color schemes in a shared cssMap
where we only want color: Text
by default?
A generic override and on the common css source?
import { cssMap } from '@atlaskit/css';
import { Icon, type IconSchema } from '@atlaskit/icon';
const styles = cssMap<IconSchema>({ primary: { color: 'var(--ds-icon-color)' } });
export default () => <Icon xcss={styles.primary} />;
Per-package css exports from every package:
import { Icon, cssMap } from '@atlaskit/icon';
const styles = cssMap({ primary: { color: 'var(--ds-icon-color)' } });
export default () => <Icon xcss={styles.primary} />;
Very loose interfaces with strict component-level interfaces
import { cssMap } from '@atlaskit/css';
import { Button } from '@atlaskit/Button';
import { Icon } from '@atlaskit/Icon';
// This `color` interface allows for both icon and text colors.
const styles = cssMap({ primary: { color: 'var(--ds-icon-color)' } });
export default () => <>
{/* This is fine because it allows icon-specific colors */}
<Icon xcss={styles.primary} />
{/* This errors because it doesn't allow icon colors */}
<Button xcss={styles.primary} />
</>
Currently, the loose
XCSSProp
allows makers to type anxcss
prop that only accepts certain CSS properties (for example, limiting a text component to only acceptcolor
. Andcreate-strict-api
allows libraries to create a restrictedXCSSProp
with limited values.However, there's no lightweight approach for a component to customize
XCSSProp
to accept both a restricted set of properties, and restricted values. After pairing on the issue with @itsdouges , he suggested the following change!This PR augments
XCSSProp
to accept an object as the first genericTAllowedProperties
, in addition to the existing string union type. When TAllowedProperties is set to an object, the required properties for XCSSProp are set automatically, and sorequiredProperties
is set tonever
.