Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CCC-50] No Build #266

Merged
merged 13 commits into from
Jan 31, 2025
2 changes: 0 additions & 2 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ jobs:
run: yarn prettier-check
- name: Build CSS
run: yarn build:css
- name: Build SCSS
run: yarn build:scss
- name: Build Tokens
run: yarn build:tokens
- name: Build Storybook
Expand Down
2 changes: 1 addition & 1 deletion .storybook/manager-head.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<style lang="sass">
<style lang="css">
button[data-action='collapse-root'] {
color: hsl(273, 22%, 18%);
text-transform: capitalize;
Expand Down
24 changes: 14 additions & 10 deletions .storybook/preview.scss → .storybook/preview.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@import './src/optics';
@import '../src/optics';

@import './src/recipes/domains-sidebar';
@import './src/recipes/16six-sidebar';
@import './src/recipes/aligned-header';
@import '../src/recipes/domains-sidebar';
@import '../src/recipes/16six-sidebar';
@import '../src/recipes/aligned-header';

@import 'https://fonts.googleapis.com/css2?family=Tilt+Neon&display=swap';

Expand Down Expand Up @@ -59,12 +59,12 @@
height: 0;
}

// Allow the "Show Code" button to appear above the footer in examples.
/* Allow the "Show Code" button to appear above the footer in examples. */
.docs-story div:last-child {
z-index: 1;
}

// Transition Demos
/* Transition Demos */
.transition-demo {
display: inline-block;
padding: var(--op-space-medium);
Expand Down Expand Up @@ -165,7 +165,11 @@
}
}

// Prevent our tag component from interfering with the docs
.text-alignment-demo {
width: 400px;
}

/* Prevent our tag component from interfering with the docs */
.language-html {
.tag {
display: initial;
Expand All @@ -178,7 +182,7 @@
}
}

// Company Card
/* Company Card */
.card.card--company {
display: flex;
align-items: center;
Expand All @@ -192,15 +196,15 @@
gap: var(--op-space-x-large);

.card__info-logo {
width: calc(var(--op-size-unit) * 24); // 96px
width: calc(var(--op-size-unit) * 24); /* 96px */
}

p {
margin: 0;
}
}

// --op-breakpoint-small
/* --op-breakpoint-small */
@media (width <= 768px) {
flex-direction: column;

Expand Down
2 changes: 1 addition & 1 deletion .storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const preview = {
},
}

import './preview.scss'
import './preview.css'

export default preview

Expand Down
18 changes: 9 additions & 9 deletions .stylelintrc.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"extends": ["stylelint-config-standard-scss", "stylelint-config-idiomatic-order", "stylelint-config-prettier-scss"],
"plugins": ["stylelint-scss", "stylelint-prettier"],
"overrides": [
{
"files": ["**/*.scss"],
"customSyntax": "postcss-scss"
}
],
"extends": ["stylelint-config-idiomatic-order"],
"plugins": ["stylelint-prettier"],
"overrides": [],
"rules": {
"prettier/prettier": true,
"custom-property-pattern": ["(?<=op-)", { "message": "CSS variables should be prefixed with op-" }],
"custom-property-pattern": [
"(?<=op-)",
{
"message": "CSS variables should be prefixed with op-"
}
],
"selector-class-pattern": null
}
}
56 changes: 23 additions & 33 deletions NEW_COMPONENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,44 @@

To create a new CSS component, follow these steps:

1. Start by defining a Sass `%{component-name}-global` placeholder for the component. This placeholder will serve as the base style for the component and all its variants.
2. Extend the default class and all variants of the component with the global placeholder you defined in the previous step. This ensures that the base style is applied consistently across all variations.
3. When creating variants of the component, use the following syntax: `.{component-name}-{variant}`. Variants are top-level components that have distinct styles or functionalities.
4. For stylistic tweaks that apply to all variants, use modifiers following the BEM (Block, Element, Modifier) syntax. The modifier class should be in the format: `.{component-name}--{modifier}`.

<!-- TODO: This distintion should exist in the main docs as well, not just in the dev instructions. Understanding how to consume components in your app and know the distinctions here is a good idea. -->

## Variant vs. Modifier

A variant is a top-level component that has distinct styles or functionalities. For example, a button component can have a primary variant that has a different color and hover state than the default button. A modifier is a class that modifies the style of a component. For example, a button component can have a disabled modifier that changes the color and cursor of the button. Modifiers apply to all Variants.
1. Start by defining a css `.{component-name}` selector for the component. This will serve as the base style for the component and all its variants.
2. Create modifiers for any all variants of the component you defined in the previous step. This ensures that the base style is shared consistently across all variations.
3. When creating variants of the component, use the following syntax: `.{component-name}--{variant}`. It can be helpful to nest these under the main class with a `&.{component-name}--{variant}` to ensure they only work with that component.
4. For stylistic tweaks that apply to all variants, use modifiers following the BEM (Block, Element, Modifier) syntax. The modifier class should be in the format: `.{component-name}--{modifier}` just like the other variants.

To illustrate these concepts, let's consider an example of a button. You can use the following template as a guide:

```scss
// Define the global placeholder for the button component
%button-global {
// Base styles for the button
```css
/* Define the main component */
.btn {
/* Base styles for the button */

// Hover state
/* Hover state */
&:hover {
// Styles for the hovered button modifier
// ...
/*
Styles for the hovered button modifier
...
*/
}

// Modifier: Large button
/* Modifier: Large button */
&.btn--large {
// Styles for the large button modifier
/* Styles for the large button modifier */
}

// Modifier: Disabled button
/* Modifier: Disabled button */
&.btn--disabled,
&:disabled {
// Styles for the disabled button modifier
/* Styles for the disabled button modifier */
}
}

// Default button class extending the global styles
.btn {
@extend %button-global;
// Specific styles for the default button variant
// ...
}

// Variant: Primary button
.btn-primary {
@extend %button-global;
// Specific styles for the primary button variant
// ...
/* Variant: Primary button */
.btn.btn--primary {
/*
Specific styles for the primary button variant
...
*/
}
```

Expand Down
20 changes: 9 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

</div>

Optics is an scss package that provides base styles and components that can be integrated and customized in a variety of projects.
Optics is an css package that provides base styles and components that can be integrated and customized in a variety of projects.

## Installation

Expand All @@ -30,16 +30,14 @@ yarn add @rolemodel/optics

### Import

If you are using webpack to compile, you can add this import to the top of your root level `scss` file.
You can add this import to the top of your root level `css` file.

```scss
@import '@rolemodel/optics';
```

If you are using a different compiler such as Dart Sass, you may need to reference the scss file directly.

```scss
@import '@rolemodel/optics/dist/scss/optics';
```css
@import '@rolemodel/optics'; /* Using webpack to compile */
/* Or */
@import '@rolemodel/optics/dist/css/optics'; /* Using a different compiler or no compiler */
/* Or */
@import '@rolemodel/optics/dist/css/optics.min.css'; /* If you want a single file with all the styles in it. */
```

## Documentation
Expand All @@ -65,7 +63,7 @@ Add the following above a group to categorize the tokens.

### Component Documentation

For instructions on how to create a new component, see [Process for Creating New Components](./NEW_COMPONENT.MD)
For instructions on how to create a new component, see [Process for Creating New Components](./NEW_COMPONENT.md)

Additional stories can be added using the following command, or copying an existing story.

Expand Down
7 changes: 1 addition & 6 deletions build_token_json.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,7 @@ try {
fs.readdir(source, { withFileTypes: true }, (_errors, files) => {
let variables = {}
files
.filter(
(directoryEntry) =>
directoryEntry.isFile() &&
directoryEntry.name !== 'dark_mode_tokens.scss' &&
directoryEntry.name !== 'index.scss'
)
.filter((directoryEntry) => directoryEntry.isFile() && directoryEntry.name !== 'index.css')
.forEach((directoryEntry) => {
const fileContents = fs.readFileSync(`${source}/${directoryEntry.name}`)
const matches = fileContents.toString().match(/^\s*--.*?(?=;)/gm)
Expand Down
2 changes: 1 addition & 1 deletion optics-design-system.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"settings": {
"prettier.configPath": ".prettierrc.json",
"stylelint.configFile": ".stylelintrc.json",
"stylelint.validate": ["css", "scss"],
"stylelint.validate": ["css"],
"editor.codeActionsOnSave": {
"source.fixAll.stylelint": "always",
},
Expand Down
23 changes: 9 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"name": "@rolemodel/optics",
"version": "1.12.0",
"version": "2.0.0",
"packageManager": "[email protected]",
"description": "Optics is an scss package that provides base styles and components that can be integrated and customized in a variety of projects.",
"main": "dist/scss/optics.scss",
"description": "Optics is a css package that provides base styles and components that can be integrated and customized in a variety of projects.",
"main": "dist/css/optics.css",
"scripts": {
"test": "exit 0",
"build": "yarn build:css && yarn build:scss && yarn build:tokens",
"build:css": "sass src/optics.scss dist/css/optics.css --load-path=node_modules/",
"build:scss": "rsync -a src/ dist/scss --exclude stories",
"build": "yarn build:css && yarn build:css-min && yarn build:tokens",
"build:css": "mkdir -p dist/css; rsync -a src/ dist/css --exclude stories",
"build:css-min": "postcss src/optics.css -o dist/css/optics.min.css",
"build:tokens": "node build_token_json --source=src/core/tokens --output=dist/tokens/tokens.json",
"storybook": "storybook dev -p 6006 --docs",
"build-storybook": "storybook build --docs",
"lint": "yarn lint:js && yarn lint:css",
"lint-fix": "yarn lint:js --fix && yarn lint:css --fix",
"lint:js": "eslint 'src/stories/**/*.js'",
"lint:css": "stylelint 'src/**/*.(scss|css)'",
"lint:css": "stylelint 'src/**/*.css'",
"prettier": "prettier -w .",
"prettier-check": "prettier -c .",
"sanity-check": "yarn lint && yarn prettier && yarn build && yarn build-storybook && rm -rf ./dist && rm -rf ./storybook-static",
Expand All @@ -30,7 +30,6 @@
"CSS",
"System",
"RoleModel",
"SCSS",
"Optics"
],
"author": "RoleModel Software",
Expand Down Expand Up @@ -64,19 +63,15 @@
"eslint-plugin-storybook": "^0.6.13",
"generate-template-files": "^3.2.1",
"postcss": "^8.4.38",
"postcss-scss": "^4.0.9",
"postcss-cli": "^11.0.0",
"postcss-import": "^16.1.0",
"prettier": "^3.0.0",
"sass": "^1.77.2",
"sass-loader": "^14.1.0",
"storybook": "^8.1.3",
"storybook-design-token": "^3.1.0",
"style-loader": "^3.3.3",
"stylelint": "^16.2.1",
"stylelint-config-idiomatic-order": "^10.0.0",
"stylelint-config-prettier-scss": "^1.0.0",
"stylelint-config-standard-scss": "^13.0.0",
"stylelint-prettier": "^5.0.0",
"stylelint-scss": "^6.1.0",
"vite": "^5.2.11"
},
"peerDependencies": {
Expand Down
3 changes: 3 additions & 0 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
plugins: [require('postcss-import')],
}
2 changes: 1 addition & 1 deletion src/components/form.css
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ textarea.form-control:not([type='radio'], [type='checkbox']) {
gap: var(--op-space-x-small);
grid-auto-rows: auto;
grid-template-columns: auto 1fr;
padding-block: var(--op-space-small) 0;
padding-block: var(--op-space-small);
padding-inline: 0;

/* Group Alignment */
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/components/sidebar.css
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
}

/* Primary */
.sidebar--primary {
&.sidebar--primary {
--_op-sidebar-background-color: var(--op-color-primary-plus-six);
--_op-sidebar-text-color: var(--op-color-primary-on-plus-six);
--_op-sidebar-border-color: var(--op-color-primary-plus-four);
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions src/optics.scss → src/optics.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Third party Vendors
/* Third party Vendors */
@import 'modern-css-reset/dist/reset';

// Tokens
/* Tokens */
@import 'core/tokens';

// Base styles and utilities
/* Base styles and utilities */
@import 'core/base';
@import 'core/layout';
@import 'core/utilities';

// Components
/* Components */
@import 'components';
12 changes: 6 additions & 6 deletions src/stories/Components/Accordion/Accordion.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ Accordion classes are built on the `details` and `summary` html elements. They p
Accordion can be used as a standalone component, however, it does have a few dependencies. To see a full dependency list, see [Dependency Graph](?path=/docs/overview-selective-imports--docs#dependencies)

```css
// Depends on
@import '@rolemodel/optics/dist/scss/core/tokens';
@import '@rolemodel/optics/dist/scss/core/base';
@import '@rolemodel/optics/dist/scss/components/icon';
/* Depends on */
@import '@rolemodel/optics/dist/css/core/tokens';
@import '@rolemodel/optics/dist/css/core/base';
@import '@rolemodel/optics/dist/css/components/icon';

// Component
@import '@rolemodel/optics/dist/scss/components/accordion';
/* Component */
@import '@rolemodel/optics/dist/css/components/accordion';
```

## Variations
Expand Down
2 changes: 1 addition & 1 deletion src/stories/Components/Alert/Alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const createAlert = ({
element.innerHTML += ' \n' // Formatting Hack

if (dismissible) {
const iconButton = createButton({ priority: 'default', icon: 'close', pill: true, noBorder: true })
const iconButton = createButton({ variant: 'default', icon: 'close', pill: true, noBorder: true })
iconButton.classList.add('alert__icon')
element.appendChild(iconButton)
}
Expand Down
Loading