Skip to content

Conversation

dstaley
Copy link
Member

@dstaley dstaley commented Aug 16, 2024

Description

This PR contains a complete implementation of the appearance prop for the new AIO components. Notable changes from the existing appearance prop include the dropping of arbitrary CSS (such as pseudo elements) and the removal of component-specific styles like appearance={{ elements: { signIn: { ... } } }}.

This PR also contains the following sub-PRs:

Checklist

  • npm test runs as expected.
  • npm run build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Copy link

changeset-bot bot commented Aug 16, 2024

🦋 Changeset detected

Latest commit: 1ecaaed

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@clerk/ui Patch

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

<AppearanceProvider appearance={{ layout: { unsafe_disableDevelopmentModeWarnings: devMode === 'off' } }}>
<style
dangerouslySetInnerHTML={{
__html: css,

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

DOM text
is reinterpreted as HTML without escaping meta-characters.
DOM text
is reinterpreted as HTML without escaping meta-characters.
DOM text
is reinterpreted as HTML without escaping meta-characters.
@dstaley dstaley marked this pull request as ready for review August 28, 2024 18:31
/**
* Union of all valid descriptors used throughout the components.
*/
export type DescriptorIdentifier = 'alert' | 'alert__error' | 'alert__warning' | 'alertRoot' | 'alertIcon';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will definitely want to work out an approach for naming here. I think this was just for testing to start. But ideally we have a convention for underscore vs camelcase etc.

Comment on lines +11 to +37
export const layoutStyle = {
alert: {
className: 'border px-4 py-3',
},
alert__warning: {},
alert__error: {},
alertRoot: {
className: 'flex gap-x-2',
},
alertIcon: {
className: 'mt-px shrink-0 *:size-4',
},
} satisfies ParsedElementsFragment;

export const visualStyle = {
alert: {
className: 'leading-small rounded-md text-base',
},
alert__warning: {
className: 'text-warning bg-warning/[0.06] border-warning/[0.12]',
},
alert__error: {
className: 'text-danger bg-danger/[0.06] border-danger/[0.12]',
},
alertRoot: {},
alertIcon: {},
} satisfies ParsedElementsFragment;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since both the layout and visual styles are needed for each component (I think), have you considered a helper function that'd solve some of the need to have empty objects defined here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will also have a good amount of these objects for files like the card component which has a good amount of nested components https://github.com/clerk/javascript/blob/main/packages/ui/src/primitives/card.tsx

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The empty objects are a type checking requirement, but after talking with Bryce we decided to move to a runtime validation approach instead. In a future PR, we'll be able to remove these empty objects, and our useAppearance hook will automatically create the empty objects without us needing to specify them.

} from '~/contexts/AppearanceContext';
import * as Icon from './icon';

export const layoutStyle = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am still not super sold on the layout naming for the based styles. But we can start with it and iterate if we want to change.

Comment on lines -23 to -30
function FirstFactorConnections({
isGlobalLoading,
hasConnection,
}: {
isGlobalLoading: boolean;
hasConnection: boolean;
}) {
const { t } = useLocalizations();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these changes meant to be here? 👀

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see yes! Alex had a few PRs targeting this branch 👍


export { AppearanceProvider, useAppearance };

if (import.meta.vitest) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love that you can test local functions without having to export them!

return result;
}

function mergeAppearance(a: Appearance | null | undefined, b: Appearance | null | undefined): Appearance | null {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be helpful to outline the merging heuristic in prose in a JSDoc. 👀

Copy link
Member

@alexcarpenter alexcarpenter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a solid foundation to build from. I am interested in getting this in sooner than later, and continue iterating on it.

Copy link
Member

@brkalow brkalow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏 great start!

@dstaley dstaley merged commit a6a715d into main Sep 4, 2024
20 checks passed
@dstaley dstaley deleted the ds.feat/elements-appearance-prop branch September 4, 2024 19:33
wobsoriano pushed a commit that referenced this pull request Feb 8, 2025
Co-authored-by: Alex Carpenter <im.alexcarpenter@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants